Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
Aeleas

IK armies aiming far from target ?

Question

I really need to fix this. I tried so much things but nothing could fix it. My project is RTS style game. Where player or enemy auto aiming at target.

I have problem with IK that can't aiming correctly at target. The head is look at target without any problem, but the chest and armies pointing away from target !!?

 

image.png

 

Here is my script, it looks long but it really simple one

Please login or register to see this code.

Here is scene file 26mb

Please login or register to see this link.

 

Could anyone here tell me why armies not pointing at target ?

It's from the script or bones ?

Share this post


Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Im 99% sure that the problem is caused by the animations. When I was working on my TP character controller, I wanted to separate the upper and lower body and play different animations on them. Well, I was able to do that, but the different animations had affected the other. I couldn't find any solution to it, so I had to setup a whole new animation controller which contains a shitload of animations, and plays the correct one based on the active state :/

  • Like 1

Share this post


Link to post
Share on other sites
  • 0

Not 100% sure about ik, but this problem persists even without ik. It's because (atleast in my experiences) the look bone (spine1 or whichever your look bone is) is not facing at default directly forward. So it looks at a target, it looks like it's looking somewhere else, even tho the look is actually facing the direction it's supposed to.

 

my personal fix has always between to add an offset to the target position (look position). So instead of LookAt(t.position) it would be LookAt(t.position + offsetVector). <<<---example, I know you don't use look at. Just showing an offset vector to the look position

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

image.png

Here is my avatar bones. do you see anything wrong ?

I tried to do what you said but nothing happen. here is my script.

Please login or register to see this code.

could you look at the file and check whether is something wrong with bones ?

 

Share this post


Link to post
Share on other sites
  • 0

It would be more like: mAnimator.SetLookAtPosition(target.position - (Vector3.up * offsetAmount)); you actually just multiplied the look target for the head transform, that's why your not seeing any results. The head transform is fine, you have to alter the spine, which is what I'm guessing your SetLookAtPosition thing is doing

  • Like 1

Share this post


Link to post
Share on other sites
  • 0

Yes, my problem is with the spine not the head. I used the spine but i didn't notes anything so I tried with the head. I really hope to find a way to fix this.

I did what you said but i get error on last part. I recode my script 

Please login or register to see this code.

I get error "Operator '*' cannot be applied to operands of type 'UnityEngine.Vector3' and 'UnityEngine.Vector3'".

Also, Why i don't use spine bone on OnAnimatorIK function ?

 

Share this post


Link to post
Share on other sites
  • 0

mAnimator.SetLookAtPosition(target.position - (Vector3.up * 0.5f));

 

or the same thing but less class instances:

 

mAnimator.SetLookAtPosition(target.position - new Vector3(0, 0.5f, 0));

 

adjust 0.5f higher or lower to get the desired outcome. You were trying to multiply up with a vector (would need to use Vector3.Scale(v1, v2)) but you need to multiply it by a float, not a vector since it's off in only one direction like in the example. You don't need the offset_target variable

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

What you said is correct. Now i can adjust the rotation of character. But still, if character moved behind target or far from it, I need again to fix the rotation manually !!

Here is my script,

Please login or register to see this code.

what else you advice me to do ? tell me.

Share this post


Link to post
Share on other sites
  • 0

Hm, thats weird. It should work at any distance or direction I'm thinking. Only thing I can think of subtracting (dis * buffer) from dy but that wouldn't be 100% accurate because it's dis is not interpolated. Like I said, I've never used ik and I actually manipulate the rotation directly instead of changing the target position. I thought it would give the same results but I guess not. Not really sure how to fix it using ik then

 

without ik it's just a simple Spine.LookAt(target); Spine.rotation.x += offsetFloat; but I think doing that with ik, it would just override the rotation change

  • Thanks 1

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

You right.

I'm think to make my animation and not using mixamo. It will take time but maybe will solve this stupid problem.

Thank you so much for what you did for me.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×