There's more...

In the Scripts directory of this recipe, you can also find a NavAgent.cs script that uses root motion without the Rigidbody component. The Update() function of the script is very similar to the NavMeshAgentWithRigidBody.cs script that we were using in this recipe, but we enable updating the position by the Nav Mesh Agent component. We only disable rotation updating. We add a OnAnimatorMove() function to the script. This method is called every frame after Unity finishes evaluating all the states in the Animator.

In that function, we set the agent.velocity vector to be the same as the velocity of the root node. We also update the transform rotation to be the same as the root node's rotation:

        void OnAnimatorMove() 
        { 
            agent.velocity = anim.deltaPosition /  
            Time.deltaTime; 
     
            transform.rotation = anim.rootRotation; 
        } 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.137.59