Master Tilemap PATHFINDING & Obstacle Avoidance in Godot 4.2

Поделиться
HTML-код
  • Опубликовано: 10 июл 2024
  • This is yet another video on pathfinding. This time we combine the best features in Godot: Pathfinding, Tilemaps and Navigation Layers. This tutorial aims to cover the usage and quirks of them, presenting how basic pathfinding is done, how to apply avoidance and finally, how to use obstacles on a Tilemap with different approaches, such as physics layers and updating navigation layers at runtime.
    Links for the discussed topics:
    Introduction to 2D Navigation - docs.godotengine.org/en/stabl...
    Navigation Agents - docs.godotengine.org/en/4.0/t...
    Godot Groups - docs.godotengine.org/en/stabl...
    Update Tiles at runtime - docs.godotengine.org/en/stabl...
    Assets:
    Tilemap and character animations: cupnooble.itch.io/sprout-land...
    --------------------
    Github repository for this project.
    github.com/cashew-olddew/godo...
    Support me on Ko-Fi: ko-fi.com/cashewolddew
    --------------------
    Chapters:
    0:00 - Project Setup
    0:30 - Pathfinding with Navigation Layers
    8:56 - More complex pathfinding
    14:35 - Pathfinding Avoidance
    19:07 - Add obstacles on the Tilemap for Pathfinding
    #godot #gamedev #pathfinding

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

  • @diegocajiao9651
    @diegocajiao9651 8 дней назад +1

    I watched like 8 videos and read 3 articles and couldn't get it working until this video. Thank you so much for this

  • @brianmiller266
    @brianmiller266 Месяц назад +6

    This is exactly what I have been looking to understand better. Thank you

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

    This is a great explanation, thank you!

  • @howardhamaker2708
    @howardhamaker2708 Месяц назад +1

    Great Video.. Very clear and precise. Natural teacher.

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

    Holy shit i've been needing this for a long time, very nice!

  • @SideQuest_Obsessed
    @SideQuest_Obsessed Месяц назад +4

    This is an amazing video, thank you so much! Excellent pace, great teaching method, voice is clear and precise. Subscribed and a lil kofi is on the way too :)

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

      I'm really happy to hear that you like it! I hope the content gets better and better. It is especially rewarding to know that it was helpful to you. Thanks a lot for the kofi! ☕🥜

  • @_Garm_
    @_Garm_ Месяц назад +1

    Great tutorials, thank you :D some thing i would love to see in this tile-map series. is digging where you auto change the tiles around the hole area to show its an edge :)

  • @777nasenbaer
    @777nasenbaer Месяц назад

    well done!

  • @tomek3633
    @tomek3633 25 дней назад

    perfect video! thumbs up!

    • @cashewolddew
      @cashewolddew  25 дней назад

      Thanks a lot for the kind words!

  • @KalenusxD
    @KalenusxD 25 дней назад

    Holy shit, what a tutorial! thanks for this! I was having a hard time figuring out the obstacles for the tilemap layers... Thank you!

    • @cashewolddew
      @cashewolddew  25 дней назад

      Thank you so much! I'm happy it helped! 🥜

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

    This is the most perfect video regarding navigation in Godot 4 so far. Thank you. One tip I have for the obstacle navigation is to make navigation its own tilemap layer and paint on top or below of the visuals once you have your map done.

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

      Woah, that's such a neat trick. I love the idea! Thanks for this and the kind words!

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

      I had the same idea but can't make it work. It only works in layer 0 in the tilemap.

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

    ahhh you just saved me from a weeklong dead stop as i tried to figure out how to get pathfinding working in my little prototype.. thanks so much!

    • @cashewolddew
      @cashewolddew  Месяц назад +1

      So happy to hear that! Hope you have an easy time with your project! 🥜

  • @catalinimbrea2214
    @catalinimbrea2214 Месяц назад +3

    It would be interesting if it was a system behavior on chickens like: give them food and they'll get attached to you, give them nothing and they'll poke you. Anyway, good things you are doing man. Good luck in your next projects!

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

      Thanks for the encouragement! Those ideas are really cool! 🥜

  • @MuhammadRaza-yd6sg
    @MuhammadRaza-yd6sg 22 дня назад

    You're a god

  • @Jinox-i9f
    @Jinox-i9f 3 дня назад

    Hello, your video quality is excellent and has been very helpful to me. Do you have any plans to create a tutorial on using the TileMapLayer component for pathfinding? I'm having trouble effectively removing collision areas in the navigation layer when using the TileMapLayer component.

    • @cashewolddew
      @cashewolddew  3 дня назад

      I'm glad you liked the video! For sure, pathfinding is a complex subject and deserves its own series. I'm usually taking notes on what viewers want to find out about and adding them to a list.
      So, for sure, I will look into it and whatever else you think would be useful! 🥜

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

    I think just adding the call_deffered should be sufficient to let the physics_process() run once. Or alternatively, add a run_once flag (bool) for the physices_proceess. But either way works. Great video BTW

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

      Thanks!
      You have to wait for a process frame because on the first frame the NavigationServer map has not synchronized region data and any path query will return empty. If you want to learn more about that, you can check the 'Introduction to 2D Navigation' example I attached in the description. 🥜

  • @martinithechobit
    @martinithechobit 20 часов назад

    NICE TY THE BEST. CHICKEN IS BEST EXAMPLE.

  • @cjmars
    @cjmars 24 дня назад

    This is great, thank you! On avoidance - it doesn't seem to do what I thought it would do. I was hoping for a recalculated path, but instead it just creates distance between the entities. This still leads to entities not choosing another route when the direct path is obstructed. Are you aware of any means to dynamically modify the navigation layer using collision shapes on the active collision mask?
    I understand having navigation layers and collision layers as separate concerns but it would be great if there was a way to be able to connect them, at least from a navigation standpoint. I thought Navigation Obstacles would be the answer, but just act like collisions in that they will block agents but an agent will still try to path through it.

    • @cashewolddew
      @cashewolddew  24 дня назад

      Thanks for the comment! As of now I'm not aware of a way of doing that, but as a hint, I know that when you want functionality better tailored to your needs, you can work directly with the NavigationServer. While it is not as straight forward as the features shown in the video, it is more powerful.
      Hope this helps! 🥜

    • @cjmars
      @cjmars 23 дня назад

      @@cashewolddew Thank you, it gives me another avenue to explore. I've seen references to the NavigationServer before but sometimes I am blinded to a feature when there is no node for it.

    • @cashewolddew
      @cashewolddew  23 дня назад

      @@cjmars That's quite understandable! 😄If you find anything useful, I'd love to hear about it!

  • @miatribe
    @miatribe 18 дней назад

    Can you lock them to the grid? Much like how just using astar works?
    Like their next position to move to is the center of the next closest tile?

    • @cashewolddew
      @cashewolddew  18 дней назад

      I have never tried that. I could check it out, but from what I remember, I didn't see an option to do that.
      Anyway, as you said, there is AStarGrid2D, which you can use to achieve exactly that. It is not much different than this, maybe just a little more coding.
      I would be very grateful if you'd let me know if you found out it is possible. 🥜

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

    I think it's going to be even better in 4.3 - apparently every Tilemap layer will be in its own node and it will allow baking nav regions without restricting them to a single layer.

    • @cashewolddew
      @cashewolddew  Месяц назад +1

      Ooh, thanks for the great news! I'll make sure to look that up! 🥜

  • @aligulec3164
    @aligulec3164 День назад

    so cute :3

  • @danis1244
    @danis1244 17 дней назад

    hi! my project is on godot 3.5 and I have been following this tutorial for my enemies. So far it has been going great, the enemies move and chase my character. However, I can't do the last section of the video "add obstacles on the tilemap for pathfinding" due to the lack of tilemap layers in the godot version i'm working on. Do anybody knows an alternative for this on godot 3.5?

    • @cashewolddew
      @cashewolddew  16 дней назад

      What I'm doing in 4.2 is basically getting information from the obstacle layer and cutting from the navigation layer. If I remember well, in 3.5, there are no layers, but rather, you have to make multiple tilemaps.
      Isn't there a way of referencing the tilemap containing obstacles and removing the navigation at those positions in a similar fashion to what I am doing?

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

    Is the await needed if you are calling call_deferred? AFAIK call_deferred will make the function execute in the next frame

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

      Sorry just saw the docs that they do as you do!

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

      No worries! This happens because we do not want to await for the next physics frame during our ready function (because the phyiscs_process hasn't even started yet so there's nothing to wait for), but rather we want to start waiting only after the physics process started.
      Finally, the waiting is done in order to synchronize the navigation server, which, in turn, will ensure that the target is picked up properly.

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

      @@yakdoggames I really appreciate comments like yours! If there is ever something wrong in the videos I would like to have it corrected so that people struggle less and enjoy game making more 🥜

  • @goncalocascais
    @goncalocascais День назад

    Is there anyway to take the chicks collision into account when creating the pathfinding? It works PERFECTLY fine with world collisions, but if you got lots of enemies what will happen is that sometimes they will get stuck behind each other . The best example of what I want to achieve is a game with ARPG gameplay where the player is able to get surrounded by enemies for example. What happens right now is that some enemies will try to surround the player but others enemies will get stuck behind each other. In the end the real question is, is there a solution to have the NavigationAgent2D take into account other enemies when creating the pathtracing route?

    • @cashewolddew
      @cashewolddew  День назад +1

      Generally, agent avoidance could be used to make characters avoid each other. That actually recalculates the pathfinding for each chicken. However, that doesn't count them as obstacles, just as other agents to avoid.

    • @goncalocascais
      @goncalocascais День назад

      @@cashewolddew Agent Avoidance does help mitigate a little bit this issue but it definitely is not a solution. Its still incredibly easy to make them block each other unfortunately. This coupled with me being super new to godot and programing has been a huge challenge to make work :')
      Regardless of this, this tutorial is brilliant in presentation and easy of use. I managed to watch it, understand it, re-create and adapt to my needs. That says a lot about it :) Hopefully I can manage to find a solution to my issue and can move on with it to other new topics ^^

    • @cashewolddew
      @cashewolddew  День назад +1

      @@goncalocascais I really appreciate your kind words! I'll also look into it when I get some time, but if you find a solution, I'd love to know about it!

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

    Yo is there a way to add layers to this, for example the chicken ignores the house, but if i want an eagle for example to go through it while the chicken stills avoids it, is it possilble?

    • @cashewolddew
      @cashewolddew  Месяц назад +1

      Hey, that's such a nice question, I haven't thought of that. I think it is possible to add more navigation layers to the tilemap. Then, if you have layer Nav0 and Nav1, you can choose to only 'cut' layer Nav0 with the coop while leaving Nav1 as it is.
      I will look into it, but until then, if you find a solution, I would be curious to know how you did it! Thanks a lot! 🥜

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

      @@cashewolddewhey I tried to do it but for some reason adding another navigation layer to the tilemap and then setting the agents to use that one , resulted in the chickens to disappear when running the game 🤔, the only way i found is to add a navigation region node that covers all the map and setting the eagle agent navigation to the layer of that navigation(layer 2 for example) but it would be better to find a way in the navigation layers of the tilemap

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

      @@giancarloapango One thing you should take into account is making sure the navigation layer for the eagle has a different layer than the one for the chicken (yes, they are both called layers). This way, the navigations wouldn't clash. The layers I'm talking about are on the first image here: docs.godotengine.org/en/stable/tutorials/navigation/navigation_using_navigationlayers.html

  • @beeyuki5947
    @beeyuki5947 День назад

    It seems that's not true if I have a multilayer Tilemap. Is there any way to help me? I want when I click on the top of the mountain, it will find its own way up by finding the stairs and starting to climb

    • @cashewolddew
      @cashewolddew  День назад

      This could work if you changed the walls around the stairs in obstacles, similarily to how the coop is made an obstacle. I also have a video with navigation regions that bake navigation.
      Generally, those result in tighter paths. You could try those as well.

    • @beeyuki5947
      @beeyuki5947 День назад

      @@cashewolddew thx I will try this

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

    I thought in Godot 4.2, Navigation2D has no set_velocity() function?

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

      In this case, set_velocity() is used to update the agent with the parent's velocity. Godot 4.2 still has this feature. You can see an example in the navigation agents documentation: docs.godotengine.org/en/4.2/tutorials/navigation/navigation_using_navigationagents.html#doc-navigation-using-navigationagents
      Hope this helps! 🥜🥜

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

    Hey man, I think you forgot to edit out a few takes around 5:15

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

      You're my hero! Thanks a lot! It should be fixed soon. I'll try to stop editing at 1 AM from now on! 🥜

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

      @@cashewolddew Cheers, good video anyway

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

    Hi nice video. What about adding an static object without tilemap how can you avoid that ? Thanks

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

      If you still want to use navigation on a tilemap, but only add an object to avoid, then a NavigationObstacle2D. However, if you simply want to use an object with a collision, I have a tutorial on Tilemaps Pathfinding, which achieves that: ruclips.net/video/ztX4OV6Syn8/видео.htmlsi=RSGKbVj-HVRaA2B0
      Hope this helps you!