Shortest Path Considering Obstacles | AI Series Part 12




Published: 27 Apr 2021

In this video I show how to correctly choose a target to move to that is CLOSEST to the NavMeshAgent, checking the distance the NavMeshAgent would actually travel, not simply the Vector3.Distance between the two points. I also explain the crucial difference between the two and why, if you want the NavMeshAgent to travel the shortest distance, you have to do it this way. We'll utilize NavMesh.CalculatePath and NavMeshPaths to calculate the total distance a NavMeshAgent would travel to a given point, and compare which is closest.


Want to learn about the editor visualization? That’s covered here:

https://youtu.be/AsrsH2XG7yM


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-12


🏷️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.


Chapters

00:00 Intro

01:08 Scene Overview

02:21 MoveToClosestTarget.cs

06:46 Agent Setup

07:12 Demo and Distance Explanation

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.