2D NavMesh | 2D Pathfinding | Unity Game Engine (Simple & Easy)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is taher and today we're implementing the 2d nav mesh to unity 2022. we're going first to this page of github we are going to download this package code and download zip file and we are going to follow these steps right there once your back is downloaded you can extract it in your unity editor here once it's ready we are going to create a tile map rectangular and then we are going to create a little plane also a little wall okay we are going to create an agent and we are going to create an empty game object call it nav mesh for our plane and wall we are going to add nav mesh modifier and then we are going to click on the plane override area make it workable then the wall override area not workable and then for our navmesh agent we are going to add a navmesh surface 2d and we are going to rotate surface to x y and hit bake okay as you can see the blue area is a place that our agent can walk on and the nun blue area is non-walkable for our agent we are going to add navmesh asian and and also we are going to add a script and we can call it agent movement i already have the script but you can create it okay and then we are going to double click on the script okay so here where what i wrote on my script you can pause the video write everything and i'll explain in a bit okay so first of all i added a target variable of type vector3 and then i added the navmesh agent in awake we are getting the component of the agent and we are adding these two lines as the github page suggest so the agent wouldn't rotate on the surface and then in update function we are calling these two functions so the first function is set target position and it's setting the target that our agent is following when you click with the mouse button uh your target is going to be set to the mouse position on the surface and then the second function called set agent position and it's moving our agent basically it's setting its destination to the target we have okay now everything should be working if we hit play okay seems like everything has disappeared and the reason is i think the wall could be one and the agent can make it two okay so i should be able to click anywhere here and the engine should be moving and as you can see it follows the target and avoiding the wall in the middle so yes um that's a very simple to the nav mesh and lastly i'd appreciate it if you subscribe to the channel it would encourage me to do similar videos in the future thanks for watching bye
Info
Channel: The World Of Game Design
Views: 36,816
Rating: undefined out of 5
Keywords: Unity 2022, 2D NavMesh, 2D NavMeshAgent, 2D Pathfinding
Id: DGBaEuZz-RA
Channel Id: undefined
Length: 3min 10sec (190 seconds)
Published: Mon Aug 15 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.