Root Motion NavMeshAgent Animation | AI Series Part 42




Published: 27 Sep 2022

Learn how to combine a Root Motion animated model with a NavMeshAgent! This gives you all the pathing benefits and local avoidance of the Navigation System with the precise animation you expect from Root Motion.


Root Motion is a great way to remove that annoying "foot sliding" from mismatched animation vs velocity. But synchronizing that motion with a NavMeshAgent can be tricky! The NavMeshAgent knows where to go and considers local avoidance. So, there's a lot of things to consider when trying to match these two systems!


We've already learned how to animate NavMeshAgents where the NavMeshAgent drives the Animator state (way back in AI Series Part 3: https://youtu.be/wLZPM46zgUo), but in this video we're going to do it the other way - with the Animator driving the NavMeshAgent!


There are multiple ways to approach this solution. In this repository I have chosen what makes the most sense to me - correcting the position of the Root Motion to pathable areas by moving the position of the model back towards the NavMeshAgent when they are out of sync.


Gargoyle Model used here: https://assetstore.unity.com/packages/3d/characters/creatures/gargoyles-fantasy-rpg-37416?aid=1101l9QvC

It's not required to run the project, but you will need to use a different model for the Player with 1D animation, or update the "PlayerMovement.cs" to set 2D Animator parameters like it's done in "EnemyMovement.cs".


๐Ÿ‘จโ€๐Ÿ’ป As always, all code from this video is available on GitHub: https://github.com/llamacademy/ai-series-part-42


๐Ÿท๏ธSave 25% on the ultimate C# IDE: JetBrains Rider with code LLAMACADEMY: https://www.jetbrains.com/store/?section=personal&billing=yearly


๐Ÿ“š Resources ๐Ÿ“š

โšซ Root Motion: https://docs.unity3d.com/Manual/RootMotion.html

โšซ Synchronizing NavMeshAgents and Root Motion: https://docs.unity3d.com/Manual/nav-CouplingAnimationAndNavigation.html

โšซ NavMeshAgents and Other Systems: https://docs.unity3d.com/Manual/nav-MixingComponents.html

โšซ AI Series Part 3 - https://youtu.be/wLZPM46zgUo


As usual with the AI Series, we're using the NavMesh Components: https://docs.unity3d.com/Manual/NavMesh-BuildingComponents.html not the built-in navigation system.


๐Ÿงก Believe in LlamAcademy's mission and have received value from the videos? Here's how you can show your support:

๐ŸŒŸ Patreon: https://www.patreon.com/llamacademy

๐ŸŒŸ YouTube Member: https://www.youtube.com/channel/UCnWm6pMD38R1E2vCAByGb6w/join or click the Join button on any video

๐Ÿ“š Take my Unity ShaderGraph Course:

https://www.gamedev.tv/p/unity-shader-graph?affcode=45216_kuvg0bp7

๐Ÿ‘• Get yourself some LlamAcademy merch: https://llamacademy.myspreadshop.com/

๐Ÿ’ธ Use my Affiliate Link for Humble Bundles https://humblebundleinc.sjv.io/9g4ak4

๐Ÿ’ธ Publisher Sale! 50% OFF an entire publisher's Assets! Publisher changes weekly! https://assetstore.unity.com/publisher-sale?aid=1101l9QvC (affiliate)

๐Ÿ’ธ Save up to 50% on NEW Assets: https://assetstore.unity.com/?new_sale=true&orderBy=1&aid=1101l9QvC (affiliate)


Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.


Connect on Social Media

Some links may be affiliate links, which at no additional cost to you, gives LlamAcademy a small portion of the purchase.