- Home /
NavMeshAgent animation - sliding
How do you make sure that a NavMeshAgent undergoes the right transition in order to not slide - or to get stuck in the timing of an odd state?
Answer by TimHeijden · Aug 05, 2015 at 10:53 PM
I assume your animation uses root motion to move the object? In that case you can implement your own "root motion" through script.
In a script that is on the same gameObject as your animator, do the following:
void OnAnimatorMove()
{
// You'd have to set this value yourself, lots of ways to do that with the animator.
bool isMoving = true;
if (isMoving)
{
agent.velocity = CharacterAnimator.deltaPosition / Time.deltaTime;
agent.speed = CharacterAnimator.deltaPosition.magnitude / Time.deltaTime;
}
else
{
agent.velocity = Vector3.zero;
agent.speed = 0.00001f; // Setting it to 0 can cause agent to do weird stuff
}
}
You'll notice in the inspector that the animator component now notes the "Apply Root Motion" variables as "Handled By Script".
Answer by nextage575 · Nov 22, 2019 at 05:44 AM
Open this link and read out NavMesh Agent and Animator.
Your answer
Follow this Question
Related Questions
Animator - How to change the motion (Anim Clip) on a STATE through scripting? 1 Answer
How to generate Mecanim Sub-state namehash? 6 Answers
Is it possible to make empty, passing state in mecanim? 3 Answers
Checking Transitions in Animator 0 Answers
How do I make the transition between two states in the "Animator" happen instantly? 3 Answers