How to use Unity NavMesh Pathfinding! (Unity Tutorial)
Вставка
- Опубліковано 1 жов 2024
- ✅ Get the FULL course here at 80% OFF!! 🌍 unitycodemonke...
👍 Learn how to make BETTER games FASTER by using all the Unity Tools and Features at your disposal!
👇
🌍 Get my Complete Courses! ✅ unitycodemonke...
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Get my Steam Games unitycodemonke...
💬 Let's learn how to use Unity NavMesh which is the built-in Pathfinding System.
Set up your scene, define what objects are walkable, bake the NavMesh and use NavMesh Agents to traverse it.
Expand upon it with some penalties and tags along with some Jumps and Off Mesh Links.
✅ Get the FULL course here at 80% OFF!! 🌍 unitycodemonke...
👍 Learn how to make BETTER games FASTER by using all the Unity Tools and Features at your disposal!
🌍 Get Code Monkey on Steam!
👍 Interactive Tutorials, Complete Games and More!
✅ store.steampow...
If you have any questions post them in the comments and I'll do my best to answer them.
🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
See you next time!
📍 Support on Patreon / unitycodemonkey
🤖 Join the Community Discord / discord
🎮 Grab the Game Bundle at unitycodemonke...
📝 Get the Code Monkey Utilities at unitycodemonke...
#unitytutorial #unity3d #gamedev #unity #gamedev #indiegame #gamedevelopment #madewithunity #indiedev
--------------------------------------------------------------------
Hello and Welcome!
I'm your Code Monkey and here you will learn everything about Game Development in Unity using C#.
I've been developing games for several years with 8 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
I do Unity Tutorials on just about every topic, Unity Tutorials for Beginners and Unity Tutorials for Advanced users.
You can see my games at www.endlessloopstudios.com
--------------------------------------------------------------------
- Other great Unity channels:
Brackeys - / brackeys
Dani - / @danidev
Jabrils - / @jabrils
BlackthornProd - / @blackthornprod
Sykoo - / sykootv
Jason Weimann - / @unity3dcollege
Jonas Tyroller - / @jonastyroller
--------------------------------------------------------------------
- Website: unitycodemonke...
- Twitter: / unitycodemonkey
- Steam: store.steampow...
✅ Get the FULL course here at 80% OFF!! 🌍 unitycodemonkey.com/courseultimateoverview.php
👍 Learn how to make BETTER games FASTER by using all the Unity Tools and Features at your disposal!
is there some lessons about mixing navmesh for npc and a way to use it to forbid controlable Player character to go somwhere?
@@NoldoWalker I cover area types in the end of the video, you can use that to disable the player from going somewhere if you're using NavMesh to move the player.
Each agent has their mask for areas they can traverse, you can make that different for the Player or NPCs
@@CodeMonkeyUnity i mean how to prevent some character to move if it controled by player. Other words : is navmesh working same way if you control actor by keys trough AddForce / aplying new transform.position value
Friendly reminder to enable Gizmos in your scene viewfinder. Otherwise you won't see the blue navmesh.
Ultimate Unity Overview awesome keep updating thank you :)
This Navigation window is labeled as Obsolete in Unity 2022. How can I do NavMesh in the latest version of Unity?
I legit saw you today in the supermarket, recognized you by your voice.
One thing that i'd like to add is that there's a Component called NavMeshObstacle that has a few settings and can be made an obstacle at runtime without needing to be baked. That's very usefull if you make a game where the walkable area can lessen mid-game, for example a Strategy Game where you build buildings. Adding the Component to the buildings Prefab will make it so that the buildings will no longer be considered walkable for Agents, even if there is a pre-baked navmesh there
Yup, I plan to cover that and more advanced use cases in another video when I make the first course update.
@@CodeMonkeyUnity waiting
Never stop these videos. l'm a beginner. Totally the best way to learn some things even if without the course (even if l think it's cool)!
I hope you will have a great journey!
@@BeardBarians he hasn't l think
Jesus, this used to be a complete pain to get working, and now it's like 2 steps, the Unity team have smashed this! Thanks for the tutorial
Crazy.
I literally just spent today on this.
Doing the surfaces and mesh modifiers was interesting.
Insane, I was literally trying to figure out how the navmesh works and this video showed up! Thanks mate you helped me out a lot 👍
Unity has changed Nav mesh. so do you plan on updating your course?
Yup it's on my list, same thing with Analytics which also changed
First video i've seen of yours and won't be my last! Thank you very much for going through this, especially the second half where you explained every option in NavMesh. I feel a lot of tutorials show you but don't care about understanding, which leaves you dry the moment you try to change something for your own game. But now I properly understand how NavMesh works, and have utilized it great in my game! Have a great day!
I'm glad you liked the video! Thanks!
For some reason it won't let me use the drop height and jump distance no matter what i set the values to
I would like to see how to manage bunch of entities trying to achieve the same position. Sometimes, there are a kind of clamping between all moving entities or entities that seem bouncing trying to reach their goals and not stop when there are a few of them at the goal position. I think the best way to manage that is with flow fields but I would like to see an approach with only nav agents, nav obstacles and set them dynamically. Great content as usual! :)
Unity's NavMesh already has object avoidance built-in, so with the default settings you won't see them overlap.
You can see that in action in the RTS game where I used NavMesh ua-cam.com/video/y601TRfoxc4/v-deo.html
For a massive amount of agents then yeah using flow fields would probably be the better approach.
@@CodeMonkeyUnity Thank you so much for taking the time to answer it to me. And thank you for all your content as usual. The best content and explanations as usual dude, thanks!
Hey can you please do a tutorial on how to use use the LOD component in ecs?
Pro tip: if you can’t see the navmesh after baking just make sure gizmos is enabled in the scene view… 🤦♂️
Thank you so much, I did not know what is the wrong ! ... thank you
Hi,
I am a novice unity game developer and I am facing an Andriod Unity Webgl problem where my canvas elements are not getting fit on any android device screen even though I set the canvas scaler to scale with the screen size. I went through a lot of documents but I couldn't figure out the answer. Please help me solve this issue as I worked really hard on that game.
Please Help!
I am trying to use my strikepack on pc. Its been working perfectly for months but all of a sudden i keep getting error codes that say "an unhandled exception occured: system.NullReferenceException: Object reference not set to an instance of an object. at ScpControl.RootHub.OnDeviceArrival" how do i fix this? Is there anyway I can get on a phonecall or discord so I can share my screen. I really just need help with this.
you should bring a course on Unity 3D state machine, Im a new to unity, but having made a simple player controller and NPC, NPC needs some brain now
WHats the difference between setting an obstacke as static, as you have shown versus adding the "nav mesh obstacle" component via inspector? Thanks
Would this NavMesh system work with a procedurally generated world? Is there a way to bake the spawning environment as it generates in-game?
Interesting. the "official" tutorials seem to state that you need the NavMesh surface component, still in preview state, to get this working. Very confusing documentation at Unity that has caused many hours of frustration. This tutorial is great though. Thanks.
Great tutorial. Im working on a horror game and im shitting myself bc there a capsule following me and I love how easy it was
WOOHOO NEW CODE MONKEY TUTORIAL THIS IS F-CKING AMAZING
i don't wanna be harsh,cuz i love unity, but the best Navmesh pro tip is to just ... DON'T ... just don't use it, lmao.
I love UA-cam for showing UE4 user unity tutorials 😀
A good explanation. Thanks
when i click on window and ai it shows navigation and navigation obsolete but when i click navigation it only shows agent and areas and the obsolete one shows agent areas bake and object pls help
i think, i need to watch your videos
i was programming the last days, a way, my NPC is walking a street from the bottom to the top, on every crossway he had to choice which way he want to walk.
need to calculcate if he is on the walkway or on the street or is on a untagged area so, he walk back again.
currentl i begun to test a system to avoid collisions with moveable objekt or npcs..
so just with this tutorial, i loose 2 weeks of testing :/
so 2 weeks of wasted time
Ooh thanks for this. Been thinking about navmeshes recently.
I love these tutorials! I bought your Udemy course as soon as I started this video and saw the link!
Are there any plans to add a 2d pathfinding video to the course? That would help me out on a project of mine.
Thanks! I hope you're enjoying the course!
I don't think Unity's NavMesh works with 2D, maybe there's an official extension but I'm not sure.
Usually for 2D either I make my own ua-cam.com/video/alU04hvz6L4/v-deo.html
Or use the A* Pathfinding Project ua-cam.com/video/46qZgd-T-hk/v-deo.html
How do i Bake the scene through code?
Lets say i procedure generate my scene and set the static mesh of my scene... How to Bake using the code?
You can add the NavMesObstacle Component if you want things to be considered an Obstacle during runtime, that's useful for example when you build a strategy game so units don't walk through buildings you build. If you want to bake an entire navmesh during runtime then Unity can't do that by itself, but there's a plugin called High Level Navmesh Building Tools that you can download from Unity to add components that you can add to gameobjects through code to make them considered for navmesh.
@@EskChan19 thank you so much.
I will look into the tool and make tests. Thanks
Amazing lecture. Good job
2:21 bro green kinda *SUS*
Take my angry Like
Well done!
Hello, I have a problem I can´t see the debug lines of the drop height in the editor when bake the navigation, Does somebody has the same issue?, thanks
Do you see the other gizmos? The blue walkable area? If not, go into the top right corner and enable gizmos.
If you do see that, then probably means it just didn't generate any drop links, change the settings.
Is it possible to simulate a large number of people leaving a multi-story building using Unity navmesh pathfinding and probuilder?
Oh, I'm in the year of 2023, and things have been changed in the Navigation window :(
This is fantastic - would love to see this with some logic using unityVS with scenarios like the Nav agent picking up then dropping off a box at his destination. Thanks CM!
Amazing tutorial!
hi i use terrain for my map and i havbe some grass on it i want to walk on gras but if i pess bake the navmesh dont show paths on the grass pls help and ty
Ah finally, a new Codemonkey tutorial!!
anyone esle have troubles with the navmesh building outside of the objects you make for walkable. for me it always seems to put navmesh outside the scene layout, outside of the map border. i can get it to bake fine then when i adjust or add more tiles the mesh just exspands into the void with no objects even there.
can u make a tutorial on how to make tycoon games
That's a topic I'd love to cover some more, I did some videos back when I was working on Battle Royale Tycoon ua-cam.com/video/rQXr9XTu6CI/v-deo.html
This video is really helpfull thank you very much awesome work.
hello, please tell me why NavMesh UpdateUpAxis may not work?
In my game to bake the terrain it is taking a time of 1and half hours
I was wondering how to do this in 2D. is it possible to do navmesh in 2d or just 3d? 2d topdown specifically.
Unity's NavMesh only supports 3D, that's why for my 2D games I normally either used my own custom Pathfinding or the A* Pathfinding Project
ua-cam.com/video/46qZgd-T-hk/v-deo.html
ua-cam.com/video/alU04hvz6L4/v-deo.html
Thanks!
@@adm1n901 github.com/h8man/NavMeshPlus use this for 2d navmesh
In my opinion you could just turn the camera from the top so it will look like 2D.
Tysm fusion
hello can i ask something why my navmesh can't run into clone from selected character?
Бля, пацан, добавь пожалуйста субтитры на русском, я не знаю английский
I've just watched the video to learn about Unity's navigation and I have a quick question: Currently i'm using a Rigidbody to move a character but I want it to navigate around different obstacles. Do I now use the NavMeshAgent to move the character instead of using the RigidBody?
How do you increase speed without sliding too much?
Ultra Advance tutorial : Unity Navmesh on Elevator :)
Sry sir, but There are lots of tutorials of navmesh so plz sir try make tutorial on animation rigging, origin reset, Dotween, locomotion with TTP, Audio verb these are very less tutorials
very useful,thank you!
I'm glad you found the video helpful, thanks!
why i dont have links shown for drop and jump?
Is it good practice to make the player an agent in an isometric 3d game?
For example my Player has a CharacterController that handles the general movement of my character - for example it walks to the location where i clicked. But it will not avoid objects. Would it be good idea to make my player a navagent to have pathfinding? How do navagents interact with objects that already have a charactercontroller attached?
Either you would use an Agent or a CharacterController, not both since they serve the same purpose (moving the object). And yes for a point and click making the player an Agent is a great way to do it
@@CodeMonkeyUnity damn that was a fast answer, amazing that you are always around and answer questions even on older videos. Thanks a lot, i highly appreciate that
OH my gods thank you!! The old tuts i watched told me to pull up NavMeshSurfaceComponenet which I'm not sure exists anymore and I was about to have a breakdown because I didn't know how else to get the level working. THANK YOU!
Amazing as always, you've got yourself a subscriber!
I'm glad you liked the video! Thanks!
Thank you for an explanation, finally figured out the damned stairs and the jump, thanks!
Hi! Which pathfinding is better for tilemap isometric game? Astar or NavMesh?
Thanks for this contants! See you next time!
The drop and jump isint working, what do i do?
Very, very, VERY nice video. Thank you. Now I know how to use nav mesh agent.
I was looking for this exact video for weeks now. Damn, I looked through all the methods of a navmeshagent, and it turns out I have to modify the destination property... Idk, I don't think it should be like that tho
O my god so nice I don’t know that navmesh can jump form cube to another or drop thank you so much ❤
Is there a way to make the player hide from the enemy using NavMeshComponent? I'm making a game where the player has to hide from the enemy which is like a warden in order to get to the end. I want to to make the player be able to hide behind walls and avoid the wardens detection.
As always, you are informative and educational. Thank you!
I don't have the bake table only navigation what do i do
You didnt speak about nav mesh obstacle
plz continue making this types of videos plzzzz.........😊😊😍😍
Is there any way to generate off mesh links for jumping up? with a max jump height? To allow agents to jump up or climb up to another mesh
Navmesh work for 2d or only for a 3d game?
Assets\NavMesh.cs(13,9): error CS0019: Operator '-' cannot be applied to operands of type 'NavMeshAgent' and 'NavMeshAgent'
Not sure what you're trying to do, you cna't do math with a NavMeshAgent
Maybe you wanted to compare the positions instead?
@@CodeMonkeyUnity i wrote the whole code you wrote in the video, but it didnt work and showed this error (my version is 2021.1.12f1)
Hello. I have a big problem. I am developing my 3d game with procedural generation, and i want to have ai enemies. But because i have really big map with trees my navmesh is creating really long. How can i speed up it?
You can split your world into multiple scenes and bake multiple navmeshes instead of just one
@@CodeMonkeyUnity but will agent be able to go from one navmesh to another?
hey there great tutorial. I am making a Tower Defense game with maze system. I have obstacles on towers, and enemies have navmesh agents. Whenever i build towers in runtime, my enemies got lagging like stopiing 0.5 sec and moving like ministun. Do you know why, can you help please?
How are you updating the navMesh? Are you updating the entire navmesh every time?
You should only be updating the part that changes, if you do that then the navmesh should be able to handle the changes without a .5s delay
If you're already doing that then perhaps you have too many units/objects, NavMesh is great but only for simplified use cases. If you have an extreme design with tons and tons of units and towers then I would recommend you look into the A* Pathfinding Project unitycodemonkey.com/video.php?v=alU04hvz6L4
It's what I've used in my Steam games where I required thousands of units pathfinding
@@CodeMonkeyUnity Thanks for your reply. Doesnt have too much units, starting with zero units on a walkable map. Every wave spawning 20 units maximum, dont think that too much :) I am updating NavMesh surface after building or selling a tower with surface.UpdateNavMesh(surface.navMeshData); But it doesnt change anything with or without it. At runtime i think building a navMesh Obstacle; breaking agent's current path even the destination is the same. And I watched your Pathfinding Project video too; it seems grid system. But my building algorithm is on a node system.
its showing me the navigation but is not giving me the option to bake it, any ideas on what it requires in order to bake it?
oh nvm turns out I was using Navigation when I should have been using Navigation (obsolete), whoopsies!
I am working on an RTS, and thinking of using A* package from Assetstore. The dilemma is that should I use my own grid and things like breakpoints, or the NavMesh? NavMesh is much easier of course and fine-grained. But then my maps might get large. So, Code Monkey, do you have any idea if NavMesh is performant enough to be the goto tool in RTS games for characters walking around, chopping wood, etc. What is your experience?
It really depends on how big are your maps and how detailed/irregular they are, but yes in general for a RTS you do want a NavMesh
The A* Pathfinding asset is insanely performant so unless you have a giant planet sized world or thousands of units I don't think you'll find many issues.
Can you bake the navmesh at runtime? Can I change agent settings through a script?
Thanks Code Monkey! That NavMesh was driving me bananas!
Awesome. could you please make a video on Vegetation studio pro.
8:23, I have a problem, if the target position is set outside the navmesh, the agents stop moving
keep get a "Set desintion error" I click bake and it does not work
Is your floor static? Does it have a collider?
Great video ! But it feels like it's made for non-player characters only ?
Or is that also how I could make my player smoothly go up stairs ?
You can also use it for the player, either as kind of like an RTS to tell the player where to go, or just ask the NavMesh ifthe position where the player wants to go to is walkable docs.unity3d.com/ScriptReference/AI.NavMesh.SamplePosition.html
@@CodeMonkeyUnity It's weird because I replicated what you did in the video, except with a cube controlled by me, and the cube just wouldn't go up the stairs :/
Can you show how to make character selection in new unity input system
tysm, this is perfect for my rts game!
But how to make the agents be able to jump onto a higher ground?
You can manually add Nav Mesh Links
@@CodeMonkeyUnity Ok. Thanks, bro.
Can you make a tutorial on auto shooting enemies without clicking fire button
There are agent settings both in agents tab and bake tab like agent radius height etc. What is the difference?
can u make a video for baking the navmesh while in the game?
Please make visual code version
How to make the unit stay on the center of the path even in corners?
I'm too glad to watch this video. Thank You.
Please remove these tutorials with outdated versions of Unity as they cause confusion and frustration.
please make Indonesian subtitles
I spent 3 days trying to understand how to move an enemy and was so satisfied, then I see this much MUCH easier method like bruh
Whatever you did, I'm sure you learned a lot so it wasn't wasted time! Keep on learning more and more things!
Nice tutorial. My game is top-down with click to move. I'm going to use NavMesh and you helped a lot.
This video is cool explaining the basics, but how to really use it? How to add e.g. an animation when it jumps from one plattform to another? How to use it with physically driven objects etc.?
In this video I focused on the basics, I plan to cover more advanced use cases in another video when I make the first course update.
I did exactly the same as mentioned yet it hit me with a null reference expression while running the code :(
Use Debug.Log to find what is null ua-cam.com/video/5irv30-bTJw/v-deo.html
@@CodeMonkeyUnity I'm getting the same error, debug says my agent is null, but I defined it exactly as you did, everything is the same
Great video as always
Also can you make a video for working in with the ide cause every other tutorial is taking about the text editor instead of the actual ide thanks