How to know end coordinates of animation in Unity?

984 Views Asked by At

I want to know coordinates of root bone in the end of animation in Unity. I tried to put unit with Animator controller programmaticaly to the scene, play animation and execute Update() several times. But coordinates are slightly different from the real. Is there method to know accurate coordinates in the end of animation?

Upd. This code should work as it should, but it doesnt work accurately:

        animator.transform.position = new Vector3(0, 0, 0);
        animator.transform.rotation = Quaternion.Euler(0, 0, 0);            
        animator.Play(_hashName, 0, 0);
        AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
        duration = stateInfo.length;
        float t = 0;
        float delta = 0.01f;
        while (t < duration)
        {
            animator.Update(delta);
            t += delta;
        }
        Vector3 endCoords = animator.transform.position;
1

There are 1 best solutions below

0
On BEST ANSWER

Finally I found the brilliant answer on Unity3d forum.

animator.SetTarget(AvatarTarget.Root, 1.0f);
animator.Update(0);
Vector3 position = animator.targetPosition;

It works perfectly.