- Home /
Question by
ThiagoUriel · Sep 25, 2015 at 12:21 PM ·
animatorsynchronizationtransform.rotate
Animator plays after movement
Hello,
I'm facing an issue where I'm rotating a game object (the player btw) and I'd like to use the walk animation while it rotates towards the target.
What happens is, the game object first rotates and then animates (sometimes it starts walking shortly before it completely finishes rotating, but still out of synch).
Here is the code that I'm using for the rotation part:
float angle = Vector3.Angle (tr.forward, mouseTarget.transform.position - tr.position);
if (angle > 0)
{
anim.SetBool ("Walk", true);
Vector3 targetPoint = mouseTarget.transform.position;
Quaternion targetRotation = Quaternion.LookRotation (targetPoint - tr.position, Vector3.up);
tr.rotation = Quaternion.Slerp (tr.rotation, targetRotation, Time.deltaTime * 5f);
}
else
{
anim.SetBool ("Walk", false);
}
I admit that I'm still unsure how to properly synchronize calls to Animator and real transform changes (or perhaps the time it takes for these things to happen?)
Thanks in advance for your thoughts.
Cheers.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612034731im_/https://answers.unity.com/themes/thub/images/avi.jpg)