Curved NavMeshAgent Paths | AI Series Part 35




Published: 04 Jan 2022

NavMeshAgents typically move linearly between a set of points calculated by the Navigation System using NavMesh.CalculatePath() under the hood, or directly by your code. In this tutorial we'll look at how we can smooth that path to add some variance into our NavMeshAgents' paths.

To do this we'll first need to understand how Bezier Curves work. That's covered in more depth in another video I've done recently:

Smoothing Lines using Bezier Curves: https://youtu.be/u0yZb1xIyLA


Assuming you have some knowledge of how those work, we'll use a Bezier Curve to smooth out the path the Agent's path and apply some configurable path postprocessing to remove noise, ensure the agent is going in the right direction.


One question I expect may come up (because that's what I tried to do in the first place and it doesn't work ;)) but I didn't add a section in the video for:

Q: Why not just create a NavMeshPath with the smoothed corners and do NavMeshAgent.SetPath(smoothedPath)

A: You cannot modify the corners property of the NavMeshPath. The NavMeshPath must be calculated by the Navigation System itself. All properties are read only: https://docs.unity3d.com/ScriptReference/AI.NavMeshPath.html


๐Ÿ’ธ Ongoing sales ๐Ÿ’ธ

โšซ See all active asset sales on the Asset Store: https://assetstore.unity.com/?on_sale=true&orderBy=0&rows=96&clickref=1100lwtudvMJ&utm_source=partnerize&utm_medium=affiliate&utm_campaign=unity_affiliate&aid=1101l9QvC

โšซ Save 25% off your first Asset Store Order: https://prf.hn/click/camref:1101l9QvC/creativeref:1011l78340

โšซ Save up to 50% on NEW Assets: https://assetstore.unity.com/?new_sale=true&orderBy=1&aid=1101l9QvC


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.


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


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


๐Ÿงก 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.