2024 AI Pathfinding: Unity 2D Pathfinding with NavMesh tutorial in 5 minutes

GitHub project for 2D Navmesh pathfinding:
github.com/h8man/NavMeshPlus
If you want to know how to bake at runtime, you can read about it here:
github.com/h8man/NavMeshPlus/...
Join the discord server: / discord

Пікірлер: 165

  • @kodaxmax
    @kodaxmax4 ай бұрын

    For anyone having trouble getting it to bake your different zones, double check your sorting layers and z position on the transform. make sure z is 0 for all objects

  • @nik5132

    @nik5132

    4 ай бұрын

    This comment should be pinned!

  • @icab0225

    @icab0225

    4 ай бұрын

    Lifesaver

  • @user-py4sk7ht2f
    @user-py4sk7ht2f16 күн бұрын

    If you want to make the navigation mesh more dense, add "Window -> AI -> Navigation", adjust "Radius" and try Bake again.

  • @wieDASland
    @wieDASland7 ай бұрын

    By far the best tutorial to this topic. There is no offtopic, no hyperactive and stressfull voice, just getting straight to the point and showing what to do

  • @rootbindev

    @rootbindev

    7 ай бұрын

    Thank you! Yeah I felt that this was missing when I was looking for a tutorial on the subject :)

  • @qhailashnikov
    @qhailashnikov15 күн бұрын

    this is so much better than A* thank you for this

  • @Vinchuca
    @Vinchuca5 ай бұрын

    Great tutorial man, you explained so well it was really easy for me to transfer the technique to a 2d tilemap.

  • @NLPIsrael
    @NLPIsrael5 ай бұрын

    ths video is great and there are so little like this - thanx!!! i have small question -i am looking to fcreate the enemy going after the player but still stics to the walls - like a spider runing on ceiling floor and 90 degrees walls. but this video shoes the best and shortest route so he doesnt stick to the "floor in 2d like he stick to the floor when its in 3d navmesh - any way to make it stick to walls and floor?

  • @KevinMoskey
    @KevinMoskey6 ай бұрын

    Incredible tutorial, super helpful and easy to implement. I'm trying to allow the enemy to rotate while navigating. Whenever I try and make it rotate I made the updateRotation true, but then it allows rotation on all axis, only am looking for Z-Axis. Is there any way I can limit that rotation to the Z-axis only? Thanks again.

  • @HalfTangible
    @HalfTangible9 ай бұрын

    If I set updateUpAxis to false, then the agent can't move upward in my scene view. But if I comment the line out, the rotation is set to -90 on the X axis (which renders the sprite invisible on the screen). For now I have the update function setting the rotation to 0/0/0, but then the agent is constantly moving on the Y axis (albeit very slowly). Yes, I have updateRotation set to false.

  • @doctorfunfrock
    @doctorfunfrock5 ай бұрын

    I couldn't help but obey the orders of your commanding voice. Thank you!!

  • @rootbindev

    @rootbindev

    5 ай бұрын

    😂 Thank you, I'm just trying to help!

  • @Inth
    @Inth7 ай бұрын

    What a true GOLD tutorial thank you a dozen times

  • @rootbindev

    @rootbindev

    7 ай бұрын

    Thank you!

  • @academyBlue3DStudio
    @academyBlue3DStudio4 ай бұрын

    Very nice Tutorial. Easy, fast and clean.

  • @rootbindev

    @rootbindev

    4 ай бұрын

    Thank you very much!

  • @TheAtticus82
    @TheAtticus824 ай бұрын

    Dude this is a great video. Just earned a new sub!

  • @rootbindev

    @rootbindev

    4 ай бұрын

    Thank you very much!

  • @ramG__
    @ramG__2 ай бұрын

    Great Tutorial !!!! Is it possible to rotate in z axis to know the forward direction ? I wanted to add an animated movement.

  • @ambroiselebs
    @ambroiselebs5 ай бұрын

    Hi, I have this error, any ideas ? "SetDestination" can only be called on an active agent that has been placed on a NavMesh.

  • @tower1990
    @tower19903 ай бұрын

    No BS. Pure goodness. Thank you sir.

  • @rootbindev

    @rootbindev

    3 ай бұрын

    Glad I could help!

  • @ukaszgretka7987
    @ukaszgretka79873 ай бұрын

    Just tested it on 2022.3.19f1 and still works. I was straggling for a while to make it bake properly. I was able to fix it by adjusting navigation options - especially the radius. I think my map was to small to work with default values set by default for "Humanoid" agent type. Anyway, thank you for the video!

  • @rootbindev

    @rootbindev

    3 ай бұрын

    Thanks for the info!

  • @dakotamogi668
    @dakotamogi66810 ай бұрын

    Works perfectly, thank you so much :)

  • @rootbindev

    @rootbindev

    10 ай бұрын

    my pleasure

  • @BurhanuddinKalawadwala
    @BurhanuddinKalawadwala5 ай бұрын

    overlaping walkable sprite on top of obstacle is not considered, in my case i have a ground and a big empty room, upon bake 2 navmashs created outer and inner, but when i overlap a walkable sprite on a part of wall it just dosnt considered walkable. can anyone show me how to?

  • @limear
    @limear5 ай бұрын

    What about Navigation Modifier Volumes? They seem to get ignored by the baking process.

  • @seangailey9035
    @seangailey9035Ай бұрын

    Great video, thanks!

  • @rootbindev

    @rootbindev

    Ай бұрын

    Thank you for watching!

  • @omar-0082
    @omar-00827 ай бұрын

    thank you very much i tried to make it by myself but it was to hard, fast clean and perfect !

  • @andrewluhmann3841
    @andrewluhmann384110 ай бұрын

    Could this be implemented in a procedural tile-based level generation? Could the scripts be somehow applied to - for example - "Walkable" and "Obstacle" tagged tiles after they are generated?

  • @rootbindev

    @rootbindev

    10 ай бұрын

    It might be covered here github.com/h8man/NavMeshPlus/wiki/HOW-TO#bake-at-runtime

  • @user-xf4te6vd5p
    @user-xf4te6vd5p26 күн бұрын

    why does the compiler not enter _agent.SetDestination(hit.point); ?

  • @LupoNoBrain
    @LupoNoBrainАй бұрын

    Hey, when adding the components to my project I get 21 warnings like this: "Assets/NavMeshComponents/Editor/NavMeshSurfaceEditor.cs(80,13): warning CS0618: 'NavMeshVisualizationSettings.showNavigation' is obsolete: 'showNavigation is no longer supported and will be removed.'" Is this package still good to use, or do I need to resort to unitys own new AI navigation package? Any help would be appreciated, thank you.

  • @LupoNoBrain

    @LupoNoBrain

    Ай бұрын

    Nevermind, I tried to include my own naming conventions already and messed something up along the way. It works now, thanks again! :D

  • @Felipe1181
    @Felipe1181Ай бұрын

    thanks for video, works perfect for me

  • @rootbindev

    @rootbindev

    Ай бұрын

    Im Glad you liked it!

  • @soup_bone
    @soup_bone5 ай бұрын

    hmmm didn't work for me says that "Failed to create agent because it is not close enough to the NavMesh" What how do i fix this.

  • @seufcho598
    @seufcho5988 ай бұрын

    Thanks for the video! Is there a way to change the movement speed as I desire for each enemy?

  • @rootbindev

    @rootbindev

    8 ай бұрын

    My pleasure! You can change the "Speed" variable in the NavMeshAgent component

  • @DicksonWeb
    @DicksonWeb5 ай бұрын

    Urgent question. How do I bake the navigation Surface from the code? I've got a dynamic map and I cant figure it out

  • @davidalin5468

    @davidalin5468

    5 ай бұрын

    [SerializeField] private NavMeshSurface navMeshSurface; private void Awake() { navMeshSurface = GetComponent(); } //and call this function when u need to bake it private void BakeNavMesh() { // Build the NavMesh navMeshSurface.BuildNavMesh(); }

  • @superlauth
    @superlauth3 ай бұрын

    Great video! Had troubles with getting a Companion AI visible when running the game, but attaching the component: Agent Override 2d fixed the issue.

  • @RG-vv4wcRG

    @RG-vv4wcRG

    Ай бұрын

    Awesome!

  • @user-ck3jz8os7q
    @user-ck3jz8os7q5 ай бұрын

    Quick question. Navmesh Agents will over ride colliders that were not baked. They will literally walk through walls when they have a destination. how do I fix this problem?

  • @StaviKay

    @StaviKay

    3 ай бұрын

    Navmesh repositions your objects in a static fashion. Use velocity to reposition your characters and it will respect the colliders.

  • @isaacsnowcarini4808
    @isaacsnowcarini48088 ай бұрын

    for some reason when i click bake, the navmesh is not visible on the scene view i m using unity version 2021 EDIT: I had gizmos visibility toggled off lol

  • @Sindiano

    @Sindiano

    Ай бұрын

    Had the same issue. You're a lifesaver :) Thanks

  • @MagnusRazer
    @MagnusRazer2 ай бұрын

    Suppose you have a grid (it could be a TileMap2D) where the rule is that crossing diagonally has a cost of "3" and sides "2", plus your enemy has a maximum movement of "10". How to do it with NAvMeshPlus?

  • @user-fd5ln2cy5j
    @user-fd5ln2cy5j9 ай бұрын

    Having an error: "SetDestination" can only be called on an active agent that has been placed on a NavMesh. Do you have any ideas why my agent doesn't get registered on a navmesh.

  • @user-fd5ln2cy5j

    @user-fd5ln2cy5j

    9 ай бұрын

    UPD: Solved, the problem that my Nav Mesh Agent height was too low.

  • @hungchuoi1994
    @hungchuoi19945 ай бұрын

    Is it possible to make multiple enemies come to the player and stand around the player, the enemies will avoid each other like they avoid obstacles?

  • @user-pc1im3cj7y

    @user-pc1im3cj7y

    3 ай бұрын

    Have you tried giving them the "Navigation modifier" component and set the override area to not walkable?

  • @saibadhri2918
    @saibadhri29189 күн бұрын

    Can we use this for 2d platformer, if yes how? I tried adding rigidbody 2d component as like we do with A* pathfinder but it doesn't work

  • @rootbindev

    @rootbindev

    8 күн бұрын

    If you add a rigidbody2D to the player, the enemy Will still be following it like in the video

  • @makra42069
    @makra4206910 ай бұрын

    Thanks for this!!

  • @12kenbutsuri
    @12kenbutsuri8 ай бұрын

    Amazing tutorial! But I get a GUID conflict when i installed the AI navmesh from the package manager, what should i do?

  • @rootbindev

    @rootbindev

    8 ай бұрын

    Restart Unity 😄can you show me the error message?

  • @12kenbutsuri

    @12kenbutsuri

    8 ай бұрын

    Thank you, it was: GUID [455cd750f394b1c41b963b3335eae29c] for asset 'Packages/com.unity.ai.navigation/Tests/Runtime/Unity.AI.Navigation.Tests.asmdef' conflicts with: 'Assets/NavMeshComponents-master/Assets/Tests/NavMeshComponentsTestsPlaymode.asmdef' (current owner) We can't assign a new GUID because the asset is in an immutable folder. The asset will be ignored. I also get the warning: You are trying to import an asset which contains a global game manager. This is not allowed. when I put the NavMeshComponents-maste into Assets, I also get the arning: You are trying to import an asset which contains a global game manager. This is not allowed. @@rootbindev

  • @FeyFen
    @FeyFen5 ай бұрын

    Thank you!

  • @boochin
    @boochin2 ай бұрын

    Hey, does this work for movable obstacles?

  • @rootbindev

    @rootbindev

    2 ай бұрын

    Hello, I'm not sure, I haven't tried it. I guess we would have to rebake alot for every move

  • @TrungNguyen-wx7tp
    @TrungNguyen-wx7tp3 ай бұрын

    how can i make it move faster? ty!

  • @StaviKay
    @StaviKay3 ай бұрын

    Hey, I was wondering if it was possible to bake the navmesh during runtime? I'm having trouble finding the solution online.

  • @rootbindev

    @rootbindev

    3 ай бұрын

    Hello! Take a look here, search for "Bake at runtime" github.com/h8man/NavMeshPlus/wiki/HOW-TO

  • @StaviKay

    @StaviKay

    3 ай бұрын

    @@rootbindev Thank you!

  • @user-ks8vn6zn3w

    @user-ks8vn6zn3w

    3 ай бұрын

    should be also pinned 100%. and thx ♥

  • @rootbindev

    @rootbindev

    3 ай бұрын

    I will add it to the description :) ​@@user-ks8vn6zn3w

  • @dashima5879
    @dashima58792 ай бұрын

    Is there a way to use this method, but still moving enemy with Rigidbody?

  • @t33h33studio

    @t33h33studio

    2 ай бұрын

    As far as I can find, no. I'm having the exact same issue. Originally I was going to use Unity's calculatepath method and just AddForce into the direction of the next path, however, navmeshplus does not seem compatible with that. The only other option left I've not tried is finding a way to use the agent with updateposition set to false, and seeing if that path works.

  • @JaysaHGames
    @JaysaHGames6 ай бұрын

    Dude , ur godlike

  • @rootbindev

    @rootbindev

    6 ай бұрын

    Thank you very much!

  • @kanoblack6179
    @kanoblack61799 ай бұрын

    Followed your tutorial but I don't know why I can't drag the player into the target input on the enemy object. Any recommendations? Thanks in advance

  • @rootbindev

    @rootbindev

    9 ай бұрын

    Make sure you have the Enemy script attached to the Enemy object before dragging :)

  • @kanoblack6179

    @kanoblack6179

    9 ай бұрын

    @@rootbindev Thanks for this quick reply but I think I had other issue. My enemy is a prefab but my reference object was not a prefab. Fixed it tho :D

  • @MrEthan.

    @MrEthan.

    9 ай бұрын

    @@kanoblack6179 im having the same problem. how did you fix it?

  • @rootbindev

    @rootbindev

    9 ай бұрын

    @@MrEthan. If one of the objects with the script attached is a prefab, both has to be prefabs

  • @PaniniDev
    @PaniniDev10 ай бұрын

    I didn’t even know 2D pathfinding was a thing 🤯🤯

  • @rootbindev

    @rootbindev

    10 ай бұрын

    It sure is! :D

  • @massagepune5636

    @massagepune5636

    9 ай бұрын

    That's why your basics should be clear.

  • @gongjunyeol
    @gongjunyeol5 ай бұрын

    When you play, the z-value of the enemy's transform position changes even though it is 2D. This is also visible in the video.

  • @rootbindev

    @rootbindev

    5 ай бұрын

    Oh, I haven't noticed! Nice that you found it and told me about it

  • @letsplaynay9936
    @letsplaynay99363 ай бұрын

    How do I do this with multiple NPCs? I want a lot of them moving with pathfinder

  • @rootbindev

    @rootbindev

    3 ай бұрын

    duplicate it! :)

  • @creepybrainz4840
    @creepybrainz484010 ай бұрын

    Thank you so much

  • @Faytz03
    @Faytz03Ай бұрын

    When i add nav surface it says Object reference not set to an instance of an object

  • @rootbindev

    @rootbindev

    Ай бұрын

    Try restarting unity

  • @OneShotOneKill924
    @OneShotOneKill92410 ай бұрын

    i cant drag and drop the nav mesh components in the assets for some reason

  • @OneShotOneKill924

    @OneShotOneKill924

    10 ай бұрын

    nvm figured it out

  • @alexbor1209
    @alexbor12095 ай бұрын

    doesn't work in 2D. help, what am I doing wrong? I tried to repeat the tutorial in different versions, the grid is not being built

  • @rootbindev

    @rootbindev

    5 ай бұрын

    I don't know what you are doing wrong, it works for me as you can see in the tutorial :) Maybe join the discord and show what you are doing and I might be able to help

  • @user-py4sk7ht2f
    @user-py4sk7ht2f11 күн бұрын

    How do I add gravity and make it jump?

  • @rootbindev

    @rootbindev

    11 күн бұрын

    There are other tutorials for that 🙂

  • @neerajramnj7598
    @neerajramnj75987 ай бұрын

    Waiting for next video

  • @rootbindev

    @rootbindev

    7 ай бұрын

    What would you like to see?

  • @leedelcie2130
    @leedelcie21309 ай бұрын

    my game objects disappear when i add the nav mesh agent component to them. i changed their order in layer but they still wont appear

  • @rootbindev

    @rootbindev

    9 ай бұрын

    Try checking your gameobjects Z position value, is that always set to zero when you play?

  • @bobbyboi8208

    @bobbyboi8208

    6 ай бұрын

    for some reason my gameObjects z position always goes to -1.169839, any idea why?

  • @Krosenut

    @Krosenut

    6 ай бұрын

    Have you tried this : void Start() { navMeshAgent = GetComponent(); navMeshAgent.updateRotation = false; navMeshAgent.updateUpAxis=false; }

  • @wakizashidev9481
    @wakizashidev94819 ай бұрын

    My obstacle doesn't bake properly despite having it set to not walkable, any ideas why?

  • @rootbindev

    @rootbindev

    9 ай бұрын

    Hmm, hard to say without more information. Did you follow the tutorial?

  • @wakizashidev9481

    @wakizashidev9481

    9 ай бұрын

    @@rootbindev I did it all again and now it works, thank you

  • @rootbindev

    @rootbindev

    9 ай бұрын

    I'm glad to hear that it works! @@wakizashidev9481

  • @k0ah371
    @k0ah3718 ай бұрын

    thank you

  • @desientertainers9706
    @desientertainers97064 ай бұрын

    AI navigation is not present in package manager😢😢😢help me

  • @lucaselias7272
    @lucaselias72729 сағат бұрын

    Thank you, I was trying to use the tool for a week and navMashAgent didn't appear, it was because I hadn't installed the navMashAgent extension AI, no other tutorial warned about this part

  • @rootbindev

    @rootbindev

    6 сағат бұрын

    Thank you for watching!

  • @phutrancong2810
    @phutrancong281010 ай бұрын

    help, i cant reference navigation surface to bake in the code, thank you

  • @rootbindev

    @rootbindev

    10 ай бұрын

    Did you follow the tutorial? :) What happens when you press Bake?

  • @jarusa77

    @jarusa77

    10 ай бұрын

    I added the navmesh surface to my level manager "public NavMeshSurface surface;" then I can call "surface.BuildNavMesh();" to build at the start of each level or if I shift the level mid gameplay. that basically runs the bake function. Note you need to include "using NavMeshPlus.Components;"

  • @tadelisvaismedelis345
    @tadelisvaismedelis3455 ай бұрын

    can someone help me with the script? It doesnt work at all and my enemy just dissappears.

  • @rootbindev

    @rootbindev

    5 ай бұрын

    show me in discord and I might be able to help

  • @FireWorkStudio148
    @FireWorkStudio1483 ай бұрын

    Thanks )))

  • @Rayreallife
    @Rayreallife8 ай бұрын

    Please help, if I create a copy of an enemy, they appear in the corner of the map and do not move

  • @rootbindev

    @rootbindev

    8 ай бұрын

    I guess you set the enemies position somewhere

  • @Rayreallife

    @Rayreallife

    8 ай бұрын

    No, because if there is only one enemy everything works@@rootbindev

  • @WyMustIGo

    @WyMustIGo

    8 ай бұрын

    @@Rayreallife Open your wallet and pay him if you want him to solve your problems. You think everyone is here to work for free at your demand? ROFLMAO, kids...

  • @maggz2808
    @maggz28088 ай бұрын

    I cant find the nav mesh agent in the add component field

  • @rootbindev

    @rootbindev

    8 ай бұрын

    Did you follow from 4:13

  • @maggz2808

    @maggz2808

    8 ай бұрын

    Yes i did everything But. I Fixed it, problem was unknown i just did nothing for 5 min and then it popped up

  • @MMonis-ge6lh
    @MMonis-ge6lh3 ай бұрын

    its not working . i use click to to move and when i click to move at random position then player is passing through the obtacles, even though obstacles are not walkable and in the scene they are also not blue .

  • @rootbindev

    @rootbindev

    3 ай бұрын

    I'm sorry to hear that

  • @MMonis-ge6lh

    @MMonis-ge6lh

    3 ай бұрын

    @@rootbindev how can i move my player ?

  • @rootbindev

    @rootbindev

    3 ай бұрын

    thats very hard to say since there is so many different ways you could have developer your game :) maybe if you show me your code in the discord channel?@@MMonis-ge6lh

  • @Copperfoill
    @Copperfoill2 ай бұрын

    Does this work in Unity 2020?

  • @rootbindev

    @rootbindev

    2 ай бұрын

    as far as I know it should, but I'm not 100% sure

  • @saahil8096
    @saahil80966 ай бұрын

    Can this work for platformers

  • @rootbindev

    @rootbindev

    6 ай бұрын

    Yes this works for platformers, it depends on what you want to get out of it :)

  • @Shibasensei
    @Shibasensei6 ай бұрын

    Hi. I've been struggling with navmesh for months. I have watched this video a dozen times. I cannot get it to work. I add the navigation surface and the navigation collect source2d. click rotate surface to XY and unlike you, after i press bake. nothing happens

  • @Shibasensei

    @Shibasensei

    6 ай бұрын

    gizmos are on

  • @rootbindev

    @rootbindev

    6 ай бұрын

    Hi! Do you use the same version of unity as I do in this tutorial? 2022.2.8f1. Did you make a 2D project?

  • @rootbindev

    @rootbindev

    6 ай бұрын

    It might be easier to help if you join the discord server

  • @Shibasensei

    @Shibasensei

    6 ай бұрын

    i tried but the link is broken. @@rootbindev

  • @Shibasensei

    @Shibasensei

    6 ай бұрын

    project is 2d and I'm using 2022.3.10f1. @@rootbindev

  • @ms.awesome
    @ms.awesome7 ай бұрын

    okay what if I wanted the enemy to run away from the player instead

  • @ms.awesome

    @ms.awesome

    7 ай бұрын

    figured out a kinda scuffed solution of just having an object rotate around the enemy based on where the player is and making the enemy follow it

  • @rootbindev

    @rootbindev

    7 ай бұрын

    Maybe you could set the target to something else then :)

  • @rbot1768
    @rbot17689 ай бұрын

    This is a great tutorial, but when i arrive to the step of adding the ai navigation packege it wont appear. (if someone know how to solve it please tell me) :'(

  • @rootbindev

    @rootbindev

    9 ай бұрын

    I think you are using too old version of unity

  • @rbot1768

    @rbot1768

    9 ай бұрын

    ok i'll check@@rootbindev

  • @JustFor-dq5wc
    @JustFor-dq5wc5 ай бұрын

    Hmmm.. I'm not sure about performance and combability of this. Unity should add simple 2D Nav system.

  • @rootbindev

    @rootbindev

    5 ай бұрын

    I Agree

  • @flyteful
    @flyteful10 ай бұрын

    i love you

  • @rootbindev

    @rootbindev

    10 ай бұрын

  • @flyteful

    @flyteful

    8 ай бұрын

    @@rootbindev Any chance you would know how to bake at runtime as well?

  • @rootbindev

    @rootbindev

    8 ай бұрын

    @@flyteful I might make a video about it :) until then you can follow this link github.com/h8man/NavMeshPlus/wiki/HOW-TO#bake-at-runtime

  • @ThatWeirdKiidOnYT
    @ThatWeirdKiidOnYT10 ай бұрын

    There is no ai navigation in my package manager

  • @rootbindev

    @rootbindev

    10 ай бұрын

    Did you select Unity Registry in the dropdown?

  • @ThatWeirdKiidOnYT

    @ThatWeirdKiidOnYT

    10 ай бұрын

    @@rootbindev I did, I think it;s because I;m using 2020 but I can still use it with git

  • @sayochikun3288
    @sayochikun32884 ай бұрын

    01:19 !!!!!!!!!!!!!!!!

  • @rootbindev

    @rootbindev

    4 ай бұрын

    ?

  • @sayochikun3288

    @sayochikun3288

    4 ай бұрын

    @@rootbindev very important timestamp. People shouldn't skim over the video

  • @rootbindev

    @rootbindev

    4 ай бұрын

    :D That's a very good advice@@sayochikun3288

  • @braindead2813
    @braindead28134 ай бұрын

    Stop yelling!

  • @rootbindev

    @rootbindev

    4 ай бұрын

    🗣

  • @braindead2813

    @braindead2813

    4 ай бұрын

    @@rootbindev 😭 I didn't do anything wrong! Stop yelling at me!