- Home /
How to move NavMesh Agent by animation?
What's the best way to create a simple moving navmesh agent with animation? (e.g. a human enemy running to player)
I have run animation that moves the enemy (which I activate by calling Run()
function that sets some properties on Animator
) but I am not sure how to combine it with navmesh. In one tutorial I saw Standard Assets ThirdPersonController's .Move(...) used for that, but I am not sure if I should use it for that purpose, as I understand it was intended only for player characters?
Or should I use animation that runs in place?
Answer by iceberg · Sep 07, 2018 at 11:48 AM
The Unity manual has a page on this:
https://docs.unity3d.com/Manual/nav-CouplingAnimationAndNavigation.html
Answer by tormentoarmagedoom · Apr 26, 2018 at 03:43 PM
Good day.
You have to use nav mesh agents for moving objects arround the scene, and animations to other things, but not to translate the object itself.
If a gameobject have a navmeshagent component and an animator, it will be able to move "automatic" by navmesh conponent (changing it transform.position and transform.rotation), so animation must do anything except move the transform.position/rotation of the object. What can do the animation is change the localposition and localrotation of childs, but not the gameobject itself.
If helped, accept the answer and close the question!
Bye!!
What do you mean by "move automatic"? I tried 3 different models (and enabled Root motion
), but they all just float without animation.
Basically use the Nav$$anonymous$$eshAgent to move the game object around the world, and use the animator to animate the visual model, modifying local position and rotation, but don't let it move away from the game object that has Nav$$anonymous$$eshAgent on it (the animated model can be a child of the Nav$$anonymous$$eshAgent).
In a nutshell: as you said, use an animation that runs in place.
I heard that moving by animation ins$$anonymous$$d of just playing animation while agent moves the object is better? (looks more natural)
But anyway as I understand Nav$$anonymous$$eshAgent by default is supposed to activate the animation somehow automatically? If yes, how do I need to setup the animation for that? Or if I need to activate it myself, where can I do that, is there events for that? (how do I know when it starts/stops movement?)
No, it's not automatic at all. Check this manual page that gets you started. This older manual page also may be helpful with using Nav$$anonymous$$eshAgent with other components.
Your answer
Follow this Question
Related Questions
Weird jumpy motion of character in Navigation Fundamentals proect 0 Answers
Navmesh agent stops playing animation. 0 Answers
Im terrible at C# but can someone explain to me exaclty whats wrong with my script? 2 Answers
Can't get player to walk to object using NavMeshAgent 1 Answer
NavMesh Agent rotates on X axis when moving and snaps back to 0. 2 Answers