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

Поделиться
HTML-код
  • Опубликовано: 20 июл 2023
  • 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

Комментарии • 159

  • @kodaxmax
    @kodaxmax 4 месяца назад +9

    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 месяца назад +3

      This comment should be pinned!

    • @icab0225
      @icab0225 4 месяца назад

      Lifesaver

  • @wieDASland
    @wieDASland 7 месяцев назад +19

    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 месяцев назад +6

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

  • @user-py4sk7ht2f
    @user-py4sk7ht2f День назад +2

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

  • @qhailashnikov
    @qhailashnikov 9 часов назад +1

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

  • @Vinchuca
    @Vinchuca 4 месяца назад +2

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

  • @dakotamogi668
    @dakotamogi668 9 месяцев назад +4

    Works perfectly, thank you so much :)

  • @HalfTangible
    @HalfTangible 9 месяцев назад +3

    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
    @doctorfunfrock 5 месяцев назад +2

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

    • @rootbindev
      @rootbindev  5 месяцев назад +1

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

  • @Inth
    @Inth 7 месяцев назад +2

    What a true GOLD tutorial thank you a dozen times

  • @tower1990
    @tower1990 2 месяца назад

    No BS. Pure goodness. Thank you sir.

  • @makra42069
    @makra42069 9 месяцев назад

    Thanks for this!!

  • @TheAtticus82
    @TheAtticus82 4 месяца назад +1

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

    • @rootbindev
      @rootbindev  4 месяца назад

      Thank you very much!

  • @academyBlue3DStudio
    @academyBlue3DStudio 4 месяца назад

    Very nice Tutorial. Easy, fast and clean.

    • @rootbindev
      @rootbindev  4 месяца назад +1

      Thank you very much!

  • @ukaszgretka7987
    @ukaszgretka7987 3 месяца назад

    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 месяца назад +1

      Thanks for the info!

  • @KevinMoskey
    @KevinMoskey 6 месяцев назад +2

    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.

  • @seangailey9035
    @seangailey9035 29 дней назад +1

    Great video, thanks!

    • @rootbindev
      @rootbindev  29 дней назад

      Thank you for watching!

  • @andrewluhmann3841
    @andrewluhmann3841 9 месяцев назад

    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  9 месяцев назад

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

  • @Felipe1181
    @Felipe1181 28 дней назад

    thanks for video, works perfect for me

  • @omar-0082
    @omar-0082 6 месяцев назад

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

  • @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.

  • @NLPIsrael
    @NLPIsrael 5 месяцев назад +1

    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?

  • @superlauth
    @superlauth 2 месяца назад

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

  • @PaniniDev
    @PaniniDev 9 месяцев назад +1

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

    • @rootbindev
      @rootbindev  9 месяцев назад +1

      It sure is! :D

    • @massagepune5636
      @massagepune5636 8 месяцев назад

      That's why your basics should be clear.

  • @k0ah371
    @k0ah371 8 месяцев назад

    thank you

  • @seufcho598
    @seufcho598 8 месяцев назад

    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

  • @ambroiselebs
    @ambroiselebs 5 месяцев назад +1

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

  • @12kenbutsuri
    @12kenbutsuri 8 месяцев назад +1

    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

  • @isaacsnowcarini4808
    @isaacsnowcarini4808 7 месяцев назад +7

    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 19 дней назад +1

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

  • @user-fd5ln2cy5j
    @user-fd5ln2cy5j 9 месяцев назад +2

    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 месяцев назад +1

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

  • @FeyFen
    @FeyFen 5 месяцев назад

    Thank you!

  • @kanoblack6179
    @kanoblack6179 9 месяцев назад

    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

  • @JaysaHGames
    @JaysaHGames 6 месяцев назад +1

    Dude , ur godlike

    • @rootbindev
      @rootbindev  6 месяцев назад

      Thank you very much!

  • @limear
    @limear 5 месяцев назад

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

  • @neerajramnj7598
    @neerajramnj7598 7 месяцев назад +1

    Waiting for next video

    • @rootbindev
      @rootbindev  7 месяцев назад

      What would you like to see?

  • @BurhanuddinKalawadwala
    @BurhanuddinKalawadwala 5 месяцев назад

    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?

  • @creepybrainz4840
    @creepybrainz4840 9 месяцев назад

    Thank you so much

  • @user-ck3jz8os7q
    @user-ck3jz8os7q 5 месяцев назад +1

    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 2 месяца назад

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

  • @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 Месяц назад +1

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

  • @StaviKay
    @StaviKay 2 месяца назад +3

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

    • @rootbindev
      @rootbindev  2 месяца назад +2

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

    • @StaviKay
      @StaviKay 2 месяца назад +1

      @@rootbindev Thank you!

    • @user-ks8vn6zn3w
      @user-ks8vn6zn3w 2 месяца назад +1

      should be also pinned 100%. and thx ♥

    • @rootbindev
      @rootbindev  2 месяца назад +2

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

  • @boochin
    @boochin 2 месяца назад +1

    Hey, does this work for movable obstacles?

    • @rootbindev
      @rootbindev  2 месяца назад +1

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

  • @DicksonWeb
    @DicksonWeb 5 месяцев назад

    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 4 месяца назад

      [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();
      }

  • @OneShotOneKill924
    @OneShotOneKill924 9 месяцев назад

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

  • @leedelcie2130
    @leedelcie2130 9 месяцев назад

    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 месяцев назад +1

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

    • @bobbyboi8208
      @bobbyboi8208 5 месяцев назад

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

    • @Krosenut
      @Krosenut 5 месяцев назад

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

  • @user-xf4te6vd5p
    @user-xf4te6vd5p 10 дней назад

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

  • @hungchuoi1994
    @hungchuoi1994 4 месяца назад +1

    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 2 месяца назад

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

  • @wakizashidev9481
    @wakizashidev9481 9 месяцев назад

    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

  • @AleGM2010
    @AleGM2010 2 месяца назад

    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?

  • @soup_bone
    @soup_bone 5 месяцев назад

    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.

  • @Rayreallife
    @Rayreallife 8 месяцев назад

    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 месяцев назад +1

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

    • @WyMustIGo
      @WyMustIGo 7 месяцев назад

      @@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
    @maggz2808 7 месяцев назад

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

    • @rootbindev
      @rootbindev  7 месяцев назад

      Did you follow from 4:13

    • @maggz2808
      @maggz2808 7 месяцев назад

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

  • @dashima5879
    @dashima5879 2 месяца назад

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

    • @t33h33studio
      @t33h33studio Месяц назад

      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.

  • @rbot1768
    @rbot1768 8 месяцев назад

    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  8 месяцев назад

      I think you are using too old version of unity

    • @rbot1768
      @rbot1768 8 месяцев назад

      ok i'll check@@rootbindev

  • @FireWorkStudio148
    @FireWorkStudio148 2 месяца назад

    Thanks )))

  • @TrungNguyen-wx7tp
    @TrungNguyen-wx7tp 3 месяца назад

    how can i make it move faster? ty!

  • @gongjunyeol
    @gongjunyeol 4 месяца назад

    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  4 месяца назад +1

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

  • @Faytz03
    @Faytz03 26 дней назад

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

  • @letsplaynay9936
    @letsplaynay9936 3 месяца назад

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

  • @phutrancong2810
    @phutrancong2810 9 месяцев назад +1

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

    • @rootbindev
      @rootbindev  9 месяцев назад

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

    • @jarusa77
      @jarusa77 9 месяцев назад

      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;"

  • @Copperfoill
    @Copperfoill Месяц назад

    Does this work in Unity 2020?

    • @rootbindev
      @rootbindev  Месяц назад

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

  • @alexbor1209
    @alexbor1209 5 месяцев назад

    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

  • @desientertainers9706
    @desientertainers9706 4 месяца назад

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

  • @MMonis-ge6lh
    @MMonis-ge6lh 3 месяца назад +1

    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 месяца назад +2

      I'm sorry to hear that

    • @MMonis-ge6lh
      @MMonis-ge6lh 2 месяца назад

      @@rootbindev how can i move my player ?

    • @rootbindev
      @rootbindev  2 месяца назад +2

      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

  • @flyteful
    @flyteful 9 месяцев назад +1

    i love you

    • @rootbindev
      @rootbindev  9 месяцев назад

    • @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

  • @Shibasensei
    @Shibasensei 6 месяцев назад

    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.awesome 7 месяцев назад +1

    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 :)

  • @JustFor-dq5wc
    @JustFor-dq5wc 4 месяца назад

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

  • @ThatWeirdKiidOnYT
    @ThatWeirdKiidOnYT 9 месяцев назад

    There is no ai navigation in my package manager

    • @rootbindev
      @rootbindev  9 месяцев назад

      Did you select Unity Registry in the dropdown?

    • @ThatWeirdKiidOnYT
      @ThatWeirdKiidOnYT 9 месяцев назад

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

  • @tadelisvaismedelis345
    @tadelisvaismedelis345 5 месяцев назад

    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

  • @saahil8096
    @saahil8096 6 месяцев назад

    Can this work for platformers

    • @rootbindev
      @rootbindev  6 месяцев назад

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

  • @sayochikun3288
    @sayochikun3288 3 месяца назад

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

    • @rootbindev
      @rootbindev  3 месяца назад

      ?

    • @sayochikun3288
      @sayochikun3288 3 месяца назад +1

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

    • @rootbindev
      @rootbindev  3 месяца назад +2

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

  • @braindead2813
    @braindead2813 3 месяца назад +1

    Stop yelling!

    • @rootbindev
      @rootbindev  3 месяца назад +3

      🗣

    • @braindead2813
      @braindead2813 3 месяца назад +1

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