Hello everyone! I've been blown away by your response to this video. I did not expect this. I am very thankful! I have decided to create a repository for future tutorials in order to give you the option to directly copy the projects from there. For this video, the project can be found here: github.com/cashew-olddew/godot-tutorials/tree/main/4.2/1%20-%20tilemap%20pathfinding
DUDE! I can't tell you how much your video was helpful to me: I have been struggling for WEEKS to make navigation work properly with Tilemaps. I could not find any helpful insight anywhere. Your video popping in my feed was litterally a Chrismtas miracle!! THANK YOU SO MUCH
Weeks? 😮 for that time it is possibly to write own layer of graphics to replace whole godot for own code. And as result to spend 30 mins to write path-finding algorithm.
@@juliap.5375 While that might be possible for an experienced developer, I think it's important to encourage each other in the learning process. To be honest, I also had moments in my programmer journey in which I spent way more than I should have on a subject and I do not regret it, as it was a huge step towards honing my skills and becoming a better programmer. 🥜
I know it's a 7 month old video, but I just wanted to say THANK YOU. I've been spending hours on trying to figure out how to automatically detect which layers should be baked and which shouldn't be baked so that I dont have to manually set NavRegion points arounds all my objects. This was perfect, all the way through. Much love
I know it's a 7-month-old video, but I am still thrilled to get such amazing comments on it. This video is actually what got me started with Godot tutorials, and it holds a special place in my heart. So, in the same way, I just want to say: THANK YOU! 🥜
I love the fact that youtube algorithm know what kind of game im making that by now, and got recommend your video. Thanks for uploading btw, hope you channel will grow bigger👍🏻
Great video, I think you have a real talent for explaining clearly without dumbing it down too much. As is evident by the comments your content is appreciated. Good luck on your youtube journey.
Thanks for the awesome video, its well explained and clear, even for a beginner at godot with a few months experience. Remember for other beginners out there, usually the issue is between the keyboard and chair. thanks Cashew OldDew for taking the time to make these videos, it saves us from a lot of headscratching and hairloss !
Reading comments like yours brings me a lot of joy. The fact that I'm probably saving some people's time or even getting them a bit closer to releasing their game really motivates me to make more and better videos. Thanks a lot for this! 🥜
Thanks so much! Way more useful than the others. I have set Source geometry mode to "Group Explicit" and then added my TileMap and any trees etc to the "navigation_polygon_source_group". Seems it might be a bit nicer than them as a child maybe? Thanks again!
Thanks for letting me know the video helped you! At the time of making it I was not aware that you could specify the source_group, but you're right, it's much cleaner that way. Thanks for letting others know about this! 🥜
Ha ha, I know what you mean! I also thought the same thing, especially since the 'layer 0' detail can be easily overlooked. However, the good news is that they have in plan to adjust this eventually: github.com/godotengine/godot/pull/80796#issuecomment-1689234510 I'm happy I was able to help you! 🥜
Thank you very much for the tutorial. I must say though, that the Tilemap + Navigation integration looks really poor as of now - lots of unintuitive actions are required.
Thank you so much for this guide! My friends and I are developing a game and have been trying to figure out navigation for a week now. You've been very helpful. How would you like me to mention you in the credits? P.S. - I apologize for possibly misspelling some words. I don't know English very well.
Hey! very helpful video, thanks a lot! Do you really need the NavigationRegion, though? If I'm using a navigation layer painted into my tiles, that's also working fine for me.
Thanks for the kind words! Were you using multiple layers while designing your tilemap? At the moment of making the video I had some problems making it work with the navigation layer of the tiles. I'd be glad to find out there's a better way of doing this! Thanks for letting me know. I will explore it more!
@@cashewolddew I'm actually having problems with layers, but as far as I keep all navigation tiles in layer 0 of the tilemap, it looks like it's working. I'm now struggling to make the agent follow the path "more strictely" but I think that's just a configuration problem. Reading through the docs right now :)
@@iakobs If what you're looking for is a way to strictly follow a Tilemap grid, I also touched that subject in this video: th-cam.com/video/OMrDS0zlr-k/w-d-xo.html
Brilliant tutorial! Wonderfully explained. Only one issue - it seems the collision between the enemies and the fence doesn't work. In other words something seems to be going wrong with layers that you mentioned at the 15:00 mark. Any thoughts why this might happen?
Thank you for the kind words! Have you made sure that the collisions are in layer 0? Currently, it only works that way. See 16:44 and this github.com/godotengine/godot/pull/80796#:~:text=TileMap%20navigation%20mesh%20baking. Hope it helps you!
This was really useful, but I have a question: Can the enemy or "seeker" have a threshold between the collision on the tilemap? I mean, to not touch it if possible. For example, if I want to avoid an enemy to get really close to the walls but in case that there is no other way to go allow it to get closer
Sorry for the late response.. Godot supports agent avoidance which would allow the behavior you describe between an enemy and your character. docs.godotengine.org/en/4.0/tutorials/navigation/navigation_using_agent_avoidance.html I also have another video on pathfinding which also covers that. Hope this helps: th-cam.com/video/yT22SXYpoYM/w-d-xo.htmlsi=u73oSTMn8h_Lt2tq&t=875
I got most of it to work, except one thing: when I bake the navigation with a polygon that surround my tilemap (it's a dungeon tilemap, so I drew the rooms and I want to navigate inside them) it generate traversable zones Outside the rooms. The rooms are not covered in blue at all. I don't understand how to tell it to also calculate the inside of the rooms. I did the navigation layer of the tilemap, selecting all the inside bits of the tiles to mark them as navigable spaces. I dunno if I'm super clear, I can send some screenshots maybe?
What you wrote is actually very clear. Great job! To be honest, I never tried generating a navigation area on an enclosed region. I'll have to try it out myself before I can say for sure.
ACTUALLY, I remember now that I did that. I did it in the video at the 19:39 minute. As you can see, the area is enclosed, but the navigation area is generated. One thing to bear in mind is the order in which you draw the nodes. For example, here github.com/godotengine/godot/pull/80796#issuecomment-1721091034 someone said that regions weren't properly drawn when putting the region nodes in a Clock-wise order. Try putting them counter clock-wise. Hope this helped! 🥜
If you're thinking about navigation polygon recalculation based on the position of the KinematicBody2D at runtime, you can bake it with the bake_navigation_polygon method: docs.godotengine.org/en/latest/classes/class_navigationregion2d.html#class-navigationregion2d-method-bake-navigation-polygon However, I'm not sure if this would be the best solution for your problem
I saw a similar question recently. If you have the polygon set, you can bake it with the bake_navigation_polygon() method. See more here for other functions you might need: docs.godotengine.org/en/stable/classes/class_navigationregion2d.html#class-navigationregion2d-method-bake-navigation-polygon However, if you want to be able to do pathfinding easier, in case you are working with a precise tilemap, you could use Astargrid2D. I also have a pretty recent video covering that topic.
the idea behind the video works flawlessly, but I have an issue. On my testing project I have a layer for walls and another for decorations (that have collision shapes as well) and right now I can only get the pathfinding to work when setting the walls to the top spot of the layers (as the video explains and this works flawlessly). The issue comes when I want to have pathfinding to take into consideration the objects that are scattered around the map as well. Right now, my enemies get stuck on this objects. Is there any workaround for this? Great video btw mate :)
Indeed, as you noticed, this is currently a limitation. I heard there will be some more features coming regarding pathfinding and Tilemaps in Godot 4.3. However, until then, maybe you could try finding all elements on that layer and remove the navigation from there? I did a similar trick in this video: th-cam.com/video/yT22SXYpoYM/w-d-xo.html Hope this helps you!
@@cashewolddew Thanks for the video, ill give it a look! and tysm for the quick answer, as someone who is brand new to gamedev its videos like this that make or break my newbie experience ❤
@@cashewolddew IT WORKED! This is an amazing workaround and seems to work flawlessly. On your example you used code on the tilemap for just one layer, but I can add as many layers as I want to it just by using "or" if coords in get_used_cells_by_id(2) or coords in get_used_cells_by_id(1): this is line 4 at 23m32s on the other video! its working flawlessly now tysm :D
Thanks , the only problem I have is that I have a moving obstacle2d but it doesn’t get avoided (and yes it is enabled and good layers and masks) any tips?
My guess is that the obstacle does not get avoided because the area does not get recalculated based on the new position of the obstacle at each frame. There are ways to programmatically regenerate the NavigationArea2D, but it's to be seen in practice how much that would affect your performance. Another possibility would be to have a different functionality for the avoidance of the moving obstacle. For example, I'm thinking you could have an Area2D on your obstacle and when your character enters that area runs a script which makes it move away from the obstacle. I haven't tested these yet, but they should be good starting points. I'm sure that you'll manage to find a solution after some exploring! Hope that helps! 🥜 ^_^
Dude your tutorial is great and I thought I can use it with an issue I am facing in my project but unfortunately not. Either way maybe you know how I could face my problem? I have an issue with the navigation agent. I have created an enemy node, added a navigation agent node to it, set up everything and the enemy is chasing the player which is making everything work 90% good. The 10% is that it is getting stuck on trees in the map. My map has 2 layers: 1st, the base one is grass or a walkable surface where I have added a navigation layer for the nav agent 2nd layer is set on top of the 1st layer and those are different obstacles like for example trees. Can I somehow define in the navigation agent to avoid the second layer when calculating the path? My map has trees with defined collisions and my navigation agent has avoidance set for the same layers as tree collisions. No idea why it doesn't work as desired. I think I can't add navigation area to my enemy node becouse I am planning to make my maps randomly generated so i just prefer to trigger navigation and chase player around as long as he is in the chase proximity of my enemy. Any idea how or what I could do? Discord is not helping this time 😢
Are you using NavigationObstacles docs.godotengine.org/en/4.0/tutorials/navigation/navigation_using_navigationobstacles.html for avoidance? That could help. Otherwise, if the trees do not move (I hope trees don't move 😀), maybe you could define them in a similar fashion to what I did for the fence in this tutorial. Hope this helps at least a bit!
@@cashewolddew oh god. I am blind :D Seems like I haven't payed too much attention to your description but now I see that exactly this is what I need and this is the best suitable idea for me! Hours wasted because of my lack of attention :D Thanks for this video!
If you're using a Tilemap you can solve this issue by excluding the tiles from the navigation baking. I have a video in which I do precisely that: th-cam.com/video/yT22SXYpoYM/w-d-xo.html Hope it helps! 🥜
This generally happens because the pathfinding nodes are trying to generate closer and closer to your target, never quite reaching it. One way to avoid this would be adding a threshold which, once reached, stops the enemy (or swaps it from moving to attacking state). You can achieve that with 'distance_to'. If the distance from the enemy to your character is less than a set threshold (say, 10 units), then you simply don't run the pathfinding code anymore. Here's the same question asked by someone. forum.godotengine.org/t/how-do-i-stop-nodes-from-shaking-with-navigationagent2d/102/2 Hope this helps! ^_^
If you have the polygon set, you can bake it with the bake_navigation_polygon() method. See more here for other functions you might need: docs.godotengine.org/en/stable/classes/class_navigationregion2d.html#class-navigationregion2d-method-bake-navigation-polygon
I'm using a CharacterBody2D as the target instead and every time I save the scene it erases "target" from the inspector to the side and navigation doesn't work. It's still exported in the script. Is there something wrong with using CharacterBody2D as the target? Edit: I don't know for sure that this was the issue, but I use VS code as an external editor and I switched from 4.1 to 4.2 for the nav updates. Something was going on where Godot had the old enemy script within the editor but VS code had the updated script. Somehow it was mixing everything up between the 2 and when saving it would read the script from the internal editor rather than the external. So stupid and unnecessary.
I think I would look for a way to dynamically bake the map once it is generated. I see in the docs that there is a bake_navigation_polygon method which could be called in your scripts: docs.godotengine.org/en/stable/classes/class_navigationregion2d.html#class-navigationregion2d-method-bake-navigation-polygon
Is it possible to do all this from code? What I want to do is to spawn a lot of enemys continuously, automatically get the path to travel on , and when they reach the destination they despawn
If you do not mind making them follow a grid, I have a video which does the most functionality from code: th-cam.com/video/OMrDS0zlr-k/w-d-xo.html However, if you want to keep the same behavior as in this video, then most of the documentation for navigation can be found under: docs.godotengine.org/en/stable/tutorials/navigation/navigation_introduction_2d.html or in the description of this video. There are usually code equivalents for all possible actions done in the editor. Let me know if you need help with anything! 🥜
@@cashewolddew Thank you, I will watch your video. I only started working in Godot yesterday, so I only know a few things. And I have never worked in any game engine before. So if I'm stuck, I just look up videos and find a proper tutorial for it.
@@deakattila It's so great to hear that you started with this. It might not always be easy, but make sure to keep it up and you'll manage to make good games!
You are correct! move_and_slide does take delta into account so having it in our calculations doesn't make sense. Thanks for pointing that out. This shouldn't affect the overall scope of the tutorial, but I'll make sure to that watchers aware of that error.
I'm not really sure what you mean by open areas, but if you want to follow the path close to the walls, there is a neat setting a NavigationAgent2D has for path post processing: docs.godotengine.org/en/stable/classes/class_navigationpathqueryparameters2d.html#enum-navigationpathqueryparameters2d-pathpostprocessing
why would it require the collision to be in layer 0 and the region to be the parent of the tilemap? It's so arbitrary and implanting this would break my game
There also is an option to have the tilemap added to a group and then specify the group in the Geometry Source Group Name field of a navigation polygon from a navigation region 2d. Regarding layer 0, from the discussions I attached in the description, it looks like it is subject to change later on, but for now, that's how it is, sadly.
Another thing I wonder, why did you to go through all the steps of using a "NavigationRegion2D", when you could simply create a navigation layer in the Tileset, and add all walkable tiles to it? It works so much simpler, and you don't need to parent the Tilemap to the Region, Bake navigation etc. Or I am missing something?
That's actually the whole reason I made the tutorial. I expected things to work a simple as you wrote here: Put a navigation layer into the Tileset, add all walkable tiles to it. However, this was not the case. I think I spent a week or so looking for a reasonable explanation or alternative. After I managed to come up with a solution, I wanted to show it to others so they don't have to go through the same pain 🥜 However, I could revisit the topic in a future video if things get simplified or changed.
@@cashewolddew thank you for the response. Maybe I'm mistaken. But navigation absolutely works for me without NavRegion or baking. Here's my enemy code (as mentioned, the Tileset has the walkable tiles added to the navigation layer, of course): extends CharacterBody2D @export var speed := 50 @export var nav_agent : NavigationAgent2D var target : Node2D var home_position : Vector2 func _ready(): nav_agent = $NavigationAgent2D home_position = self.global_position nav_agent.path_desired_distance = 4 nav_agent.target_desired_distance = 4 func _physics_process(_delta): if nav_agent.is_navigation_finished(): return var axis = to_local(nav_agent.get_next_path_position()).normalized() velocity = axis * speed move_and_slide() func recalculate_path(): if target: nav_agent.target_position = target.global_position else: nav_agent.target_position = home_position func _on_recalculate_timer_timeout(): recalculate_path()
@@cashewolddew I see. I've dug into the problem a bit deeper and... looks like one can totally make Navigation work with just a navigation layer, however you won't be able to use layered tilemaps, which is obviously unacceptable. So only single layered tilemaps are supported without baking... too bad. Which is, incidentally, what you've already written in the video description, I should have been more attentive :)
@@cashewolddew thanks! Yes, I am looking for more ways to do it, since the approach with NavRegion2D, while definitely working, looks a bit too 'manual' or complex to implement for procedurally generated or streamed tilemaps. Will post any updates.
I think I am a bit lost. I thought you could do all the navigation in the tilemap instead of needing that additional region node to make it all come together. Is that incorrect?
I thought the same thing, especially since a Tilemap has navigation layers. However, when I tried to do exactly that I stumbled upon a lot of troubles. This was actually the reason I made this video. I tried so hard to make things work that I didn't want anyone to go through that again :D I added some notes in the description regarding those issues and some discussion on Github. I'm actively checking this and if I find that an issue is fixed or that I was not doing something properly, I'll make sure to come with an update!
@@cashewolddew I am working on something now and the stars aligned. I am using the tilemap with nav layers and it is working! If you want it, I can share. LMK.
@@JuddGledhill I'd also be interested. Was attempting to learn and use the navigation layers, struggled a bit, learned Godot 4.2 added some changes, and am now in a rabbit hole lol. This video is great, btw. Thank you.
If I remember well, tilemap layers were not a thing in godot 3.x. This would probably imply that the navigation baking for the tilemap does not work as well, as there would be no concept of 'layer 0' without layers. I hope you get the Nvidia graphics problems fixed. I'm not sure if it would help, but try checking that you also have the latest drivers for your graphics card.
Hello! Sorry for missing your comment. What do you mean by that? Is the generated region too small? Try checking if making the navigation polygon larger would help.
Hello everyone! I've been blown away by your response to this video. I did not expect this. I am very thankful!
I have decided to create a repository for future tutorials in order to give you the option to directly copy the projects from there. For this video, the project can be found here:
github.com/cashew-olddew/godot-tutorials/tree/main/4.2/1%20-%20tilemap%20pathfinding
DUDE! I can't tell you how much your video was helpful to me: I have been struggling for WEEKS to make navigation work properly with Tilemaps. I could not find any helpful insight anywhere. Your video popping in my feed was litterally a Chrismtas miracle!! THANK YOU SO MUCH
I'm really glad it helped you! Happy holidays!
Man, im still stuck on trying to call animations from my animation tree 😅😅😅
@@tylerdavault9604 Don't worry, it gets easier! Here's a peanut 🥜
Weeks? 😮 for that time it is possibly to write own layer of graphics to replace whole godot for own code. And as result to spend 30 mins to write path-finding algorithm.
@@juliap.5375 While that might be possible for an experienced developer, I think it's important to encourage each other in the learning process.
To be honest, I also had moments in my programmer journey in which I spent way more than I should have on a subject and I do not regret it, as it was a huge step towards honing my skills and becoming a better programmer. 🥜
I know it's a 7 month old video, but I just wanted to say THANK YOU.
I've been spending hours on trying to figure out how to automatically detect which layers should be baked and which shouldn't be baked so that I dont have to manually set NavRegion points arounds all my objects. This was perfect, all the way through. Much love
I know it's a 7-month-old video, but I am still thrilled to get such amazing comments on it.
This video is actually what got me started with Godot tutorials, and it holds a special place in my heart.
So, in the same way, I just want to say: THANK YOU! 🥜
@@cashewolddew ❤keep at it, good content will get the recognition eventually, I for one will surely keep watching your videos.
I love the fact that youtube algorithm know what kind of game im making that by now, and got recommend your video.
Thanks for uploading btw, hope you channel will grow bigger👍🏻
Thanks a lot for the support! 🥜
Thank you! I saw maybe 10 tutorial on how to make a pathfinding but no one of these tutorial is for godot 4.2. You saved my life
You are very welcome! :D
Bro the second I gave up on this, you pop up on my feed! THANK YOU SO MUCH!
Ha ha, I'm glad I appeared just in time! 🥜
Great video, I think you have a real talent for explaining clearly without dumbing it down too much. As is evident by the comments your content is appreciated. Good luck on your youtube journey.
Thanks for the awesome video, its well explained and clear, even for a beginner at godot with a few months experience. Remember for other beginners out there, usually the issue is between the keyboard and chair. thanks Cashew OldDew for taking the time to make these videos, it saves us from a lot of headscratching and hairloss !
Reading comments like yours brings me a lot of joy. The fact that I'm probably saving some people's time or even getting them a bit closer to releasing their game really motivates me to make more and better videos.
Thanks a lot for this! 🥜
This was SO useful, and very well-explained. Great job, homie, and thank you!
Thanks a lot! 🥜
I've been struggling with this for a couple days now and your tutorial worked quite nicely!
Glad it helped! 🥜
what an extremely powerful tool, thanks for the major insight !
thank you so much for making this video. i was able to make a simple code for an enemy in my game project ❤
this video was actually quite useful for me... got a new sub! pls make more tutorials on godot tips & tricks!
Thank you for the kind words. Will make sure to do more ^^
Thanks this has been very useful. I've been using NavigationAgent's Avoidance cause didn't know how to bake the obstacles within the polygon heheh
ohhh, I didn't knew auto tilling, that's useful
Damn I learned a lot from this tutorial, you got my sub for sure and thank for the wonderful tutorial ❤
I'm happy to hear that! Thanks a lot! 🥜
That bake button stuck me forever.
Hope you are unstuck now! ^^
Thanks so much! Way more useful than the others. I have set Source geometry mode to "Group Explicit" and then added my TileMap and any trees etc to the "navigation_polygon_source_group". Seems it might be a bit nicer than them as a child maybe? Thanks again!
Thanks for letting me know the video helped you! At the time of making it I was not aware that you could specify the source_group, but you're right, it's much cleaner that way.
Thanks for letting others know about this! 🥜
Thank you. I have issues as well with the latest build.
Ha ha, it's better if we struggle together 😅
Very helpful and well explained!
This was super helpful, thanks!
Though it would be nice if it considered all layers of the tilemap and not just the top most one ;P
Ha ha, I know what you mean! I also thought the same thing, especially since the 'layer 0' detail can be easily overlooked. However, the good news is that they have in plan to adjust this eventually: github.com/godotengine/godot/pull/80796#issuecomment-1689234510
I'm happy I was able to help you! 🥜
Thank you very much for the tutorial. I must say though, that the Tilemap + Navigation integration looks really poor as of now - lots of unintuitive actions are required.
Really need this one, thanks!
Thank you so much for this guide! My friends and I are developing a game and have been trying to figure out navigation for a week now. You've been very helpful. How would you like me to mention you in the credits?
P.S. - I apologize for possibly misspelling some words. I don't know English very well.
Woah, I would be honored to be in your credits! Cashew OldDew is fine!
I'd love to hear from you once the game is finished 🥜
Thank you so much!
谢谢,讲得很清晰
不客气 🥜
Please tell me that this is going to be an ongoing series...your tutorials are so helpf
I'm really happy to hear your feedback! I want to make more tutorials. I actually added one just yesterday 🥜
u are my hero, TYVM
Very well! Thanks )
Cool!
Hey! very helpful video, thanks a lot! Do you really need the NavigationRegion, though? If I'm using a navigation layer painted into my tiles, that's also working fine for me.
Thanks for the kind words! Were you using multiple layers while designing your tilemap? At the moment of making the video I had some problems making it work with the navigation layer of the tiles.
I'd be glad to find out there's a better way of doing this! Thanks for letting me know. I will explore it more!
@@cashewolddew I'm actually having problems with layers, but as far as I keep all navigation tiles in layer 0 of the tilemap, it looks like it's working. I'm now struggling to make the agent follow the path "more strictely" but I think that's just a configuration problem. Reading through the docs right now :)
@@iakobs If what you're looking for is a way to strictly follow a Tilemap grid, I also touched that subject in this video: th-cam.com/video/OMrDS0zlr-k/w-d-xo.html
@@cashewolddew you're god tier! thanks!
Sensei! Thanks
Brilliant tutorial! Wonderfully explained. Only one issue - it seems the collision between the enemies and the fence doesn't work. In other words something seems to be going wrong with layers that you mentioned at the 15:00 mark. Any thoughts why this might happen?
Thank you for the kind words! Have you made sure that the collisions are in layer 0? Currently, it only works that way. See 16:44 and this github.com/godotengine/godot/pull/80796#:~:text=TileMap%20navigation%20mesh%20baking. Hope it helps you!
nice tutorial
This was really useful, but I have a question: Can the enemy or "seeker" have a threshold between the collision on the tilemap? I mean, to not touch it if possible. For example, if I want to avoid an enemy to get really close to the walls but in case that there is no other way to go allow it to get closer
I think in that way it would look more natural
Sorry for the late response.. Godot supports agent avoidance which would allow the behavior you describe between an enemy and your character. docs.godotengine.org/en/4.0/tutorials/navigation/navigation_using_agent_avoidance.html
I also have another video on pathfinding which also covers that. Hope this helps: th-cam.com/video/yT22SXYpoYM/w-d-xo.htmlsi=u73oSTMn8h_Lt2tq&t=875
@@cashewolddew I already made a system of steering behaviors, but thanks tho, your tutorial was really useful to begin with
thank you :)
I got most of it to work, except one thing: when I bake the navigation with a polygon that surround my tilemap (it's a dungeon tilemap, so I drew the rooms and I want to navigate inside them) it generate traversable zones Outside the rooms. The rooms are not covered in blue at all. I don't understand how to tell it to also calculate the inside of the rooms. I did the navigation layer of the tilemap, selecting all the inside bits of the tiles to mark them as navigable spaces.
I dunno if I'm super clear, I can send some screenshots maybe?
What you wrote is actually very clear. Great job!
To be honest, I never tried generating a navigation area on an enclosed region. I'll have to try it out myself before I can say for sure.
ACTUALLY, I remember now that I did that. I did it in the video at the 19:39 minute. As you can see, the area is enclosed, but the navigation area is generated.
One thing to bear in mind is the order in which you draw the nodes. For example, here github.com/godotengine/godot/pull/80796#issuecomment-1721091034 someone said that regions weren't properly drawn when putting the region nodes in a Clock-wise order. Try putting them counter clock-wise.
Hope this helped! 🥜
Is it possibe to do this while using a moving KinematicBody2D as the obstacle?
If you're thinking about navigation polygon recalculation based on the position of the KinematicBody2D at runtime, you can bake it with the bake_navigation_polygon method: docs.godotengine.org/en/latest/classes/class_navigationregion2d.html#class-navigationregion2d-method-bake-navigation-polygon However, I'm not sure if this would be the best solution for your problem
can you bake programatically? so that we can do dynamic tilemap editing for positioning walls or breaking blocks
I saw a similar question recently. If you have the polygon set, you can bake it with the bake_navigation_polygon() method. See more here for other functions you might need: docs.godotengine.org/en/stable/classes/class_navigationregion2d.html#class-navigationregion2d-method-bake-navigation-polygon
However, if you want to be able to do pathfinding easier, in case you are working with a precise tilemap, you could use Astargrid2D. I also have a pretty recent video covering that topic.
the idea behind the video works flawlessly, but I have an issue. On my testing project I have a layer for walls and another for decorations (that have collision shapes as well) and right now I can only get the pathfinding to work when setting the walls to the top spot of the layers (as the video explains and this works flawlessly). The issue comes when I want to have pathfinding to take into consideration the objects that are scattered around the map as well. Right now, my enemies get stuck on this objects. Is there any workaround for this? Great video btw mate :)
Indeed, as you noticed, this is currently a limitation. I heard there will be some more features coming regarding pathfinding and Tilemaps in Godot 4.3. However, until then, maybe you could try finding all elements on that layer and remove the navigation from there? I did a similar trick in this video: th-cam.com/video/yT22SXYpoYM/w-d-xo.html
Hope this helps you!
@@cashewolddew Thanks for the video, ill give it a look! and tysm for the quick answer, as someone who is brand new to gamedev its videos like this that make or break my newbie experience ❤
@@cashewolddew IT WORKED! This is an amazing workaround and seems to work flawlessly. On your example you used code on the tilemap for just one layer, but I can add as many layers as I want to it just by using "or"
if coords in get_used_cells_by_id(2) or coords in get_used_cells_by_id(1):
this is line 4 at 23m32s on the other video!
its working flawlessly now tysm :D
@@goncalocascais I'm very happy you did it! Hopefully these comments will also help others. 🥜
Thanks , the only problem I have is that I have a moving obstacle2d but it doesn’t get avoided (and yes it is enabled and good layers and masks) any tips?
My guess is that the obstacle does not get avoided because the area does not get recalculated based on the new position of the obstacle at each frame. There are ways to programmatically regenerate the NavigationArea2D, but it's to be seen in practice how much that would affect your performance.
Another possibility would be to have a different functionality for the avoidance of the moving obstacle. For example, I'm thinking you could have an Area2D on your obstacle and when your character enters that area runs a script which makes it move away from the obstacle.
I haven't tested these yet, but they should be good starting points. I'm sure that you'll manage to find a solution after some exploring!
Hope that helps! 🥜 ^_^
Dude your tutorial is great and I thought I can use it with an issue I am facing in my project but unfortunately not. Either way maybe you know how I could face my problem?
I have an issue with the navigation agent.
I have created an enemy node, added a navigation agent node to it, set up everything and the enemy is chasing the player which is making everything work 90% good. The 10% is that it is getting stuck on trees in the map.
My map has 2 layers:
1st, the base one is grass or a walkable surface where I have added a navigation layer for the nav agent
2nd layer is set on top of the 1st layer and those are different obstacles like for example trees.
Can I somehow define in the navigation agent to avoid the second layer when calculating the path?
My map has trees with defined collisions and my navigation agent has avoidance set for the same layers as tree collisions. No idea why it doesn't work as desired. I think I can't add navigation area to my enemy node becouse I am planning to make my maps randomly generated so i just prefer to trigger navigation and chase player around as long as he is in the chase proximity of my enemy.
Any idea how or what I could do? Discord is not helping this time 😢
Are you using NavigationObstacles docs.godotengine.org/en/4.0/tutorials/navigation/navigation_using_navigationobstacles.html for avoidance? That could help.
Otherwise, if the trees do not move (I hope trees don't move 😀), maybe you could define them in a similar fashion to what I did for the fence in this tutorial.
Hope this helps at least a bit!
@@cashewolddew I will check navigationobstacles and if not I will just use your solution :) thanks for the reply man
@@cashewolddew oh god. I am blind :D Seems like I haven't payed too much attention to your description but now I see that exactly this is what I need and this is the best suitable idea for me! Hours wasted because of my lack of attention :D Thanks for this video!
@@noise_dev Happens to the best of us! 😄
I make the same thing but enemy is stuck on obstacle but navigarionregion2d is not baking to new shape, any idea?
If you're using a Tilemap you can solve this issue by excluding the tiles from the navigation baking. I have a video in which I do precisely that: th-cam.com/video/yT22SXYpoYM/w-d-xo.html
Hope it helps! 🥜
@@cashewolddew OMG you just saved at least 4 hours of pain in my a**. Thanks for help and quick replay
Hi, friend! Tell me, why when the enemy reaches the goal, he does not stop, but trembles? How can this be resolved using pathfinding settings?
This generally happens because the pathfinding nodes are trying to generate closer and closer to your target, never quite reaching it.
One way to avoid this would be adding a threshold which, once reached, stops the enemy (or swaps it from moving to attacking state). You can achieve that with 'distance_to'. If the distance from the enemy to your character is less than a set threshold (say, 10 units), then you simply don't run the pathfinding code anymore.
Here's the same question asked by someone. forum.godotengine.org/t/how-do-i-stop-nodes-from-shaking-with-navigationagent2d/102/2
Hope this helps! ^_^
Any idea how to bake the NavigationRegion2D at runtime?
If you have the polygon set, you can bake it with the bake_navigation_polygon() method. See more here for other functions you might need: docs.godotengine.org/en/stable/classes/class_navigationregion2d.html#class-navigationregion2d-method-bake-navigation-polygon
I'm using a CharacterBody2D as the target instead and every time I save the scene it erases "target" from the inspector to the side and navigation doesn't work. It's still exported in the script. Is there something wrong with using CharacterBody2D as the target?
Edit: I don't know for sure that this was the issue, but I use VS code as an external editor and I switched from 4.1 to 4.2 for the nav updates. Something was going on where Godot had the old enemy script within the editor but VS code had the updated script. Somehow it was mixing everything up between the 2 and when saving it would read the script from the internal editor rather than the external. So stupid and unnecessary.
I'm happy you quickly found a fix. Good job! 🥜
how would you go about using navigation regions with an automatically generated world?
I think I would look for a way to dynamically bake the map once it is generated.
I see in the docs that there is a bake_navigation_polygon method which could be called in your scripts: docs.godotengine.org/en/stable/classes/class_navigationregion2d.html#class-navigationregion2d-method-bake-navigation-polygon
Is it possible to do all this from code? What I want to do is to spawn a lot of enemys continuously, automatically get the path to travel on , and when they reach the destination they despawn
If you do not mind making them follow a grid, I have a video which does the most functionality from code: th-cam.com/video/OMrDS0zlr-k/w-d-xo.html
However, if you want to keep the same behavior as in this video, then most of the documentation for navigation can be found under: docs.godotengine.org/en/stable/tutorials/navigation/navigation_introduction_2d.html or in the description of this video. There are usually code equivalents for all possible actions done in the editor. Let me know if you need help with anything! 🥜
@@cashewolddew Thank you, I will watch your video. I only started working in Godot yesterday, so I only know a few things. And I have never worked in any game engine before. So if I'm stuck, I just look up videos and find a proper tutorial for it.
@@deakattila It's so great to hear that you started with this. It might not always be easy, but make sure to keep it up and you'll manage to make good games!
isn't delta applied automatically in the move and slide function? I wonder if it's necesary to apply that to velocity when moving the enemy
You are correct! move_and_slide does take delta into account so having it in our calculations doesn't make sense. Thanks for pointing that out. This shouldn't affect the overall scope of the tutorial, but I'll make sure to that watchers aware of that error.
@@cashewolddew I mean, yeah. I'm telling you because I used to do it. I've been enjoying watching your videos, man. Keep it up.
@@Limited_Film_Works_ Really appreciate it!
is there a way to make the pathfinding avoid open areas and be restricted to near walls?
I'm not really sure what you mean by open areas, but if you want to follow the path close to the walls, there is a neat setting a NavigationAgent2D has for path post processing: docs.godotengine.org/en/stable/classes/class_navigationpathqueryparameters2d.html#enum-navigationpathqueryparameters2d-pathpostprocessing
im trying to make a wall crawler type pathfinding@@cashewolddew
@@dreadgeIn such a case I would define his walkable area to only be the walls
why would it require the collision to be in layer 0 and the region to be the parent of the tilemap? It's so arbitrary and implanting this would break my game
There also is an option to have the tilemap added to a group and then specify the group in the Geometry Source Group Name field of a navigation polygon from a navigation region 2d. Regarding layer 0, from the discussions I attached in the description, it looks like it is subject to change later on, but for now, that's how it is, sadly.
Another thing I wonder, why did you to go through all the steps of using a "NavigationRegion2D", when you could simply create a navigation layer in the Tileset, and add all walkable tiles to it? It works so much simpler, and you don't need to parent the Tilemap to the Region, Bake navigation etc. Or I am missing something?
That's actually the whole reason I made the tutorial. I expected things to work a simple as you wrote here: Put a navigation layer into the Tileset, add all walkable tiles to it. However, this was not the case. I think I spent a week or so looking for a reasonable explanation or alternative.
After I managed to come up with a solution, I wanted to show it to others so they don't have to go through the same pain 🥜
However, I could revisit the topic in a future video if things get simplified or changed.
@@cashewolddew thank you for the response. Maybe I'm mistaken. But navigation absolutely works for me without NavRegion or baking. Here's my enemy code (as mentioned, the Tileset has the walkable tiles added to the navigation layer, of course):
extends CharacterBody2D
@export var speed := 50
@export var nav_agent : NavigationAgent2D
var target : Node2D
var home_position : Vector2
func _ready():
nav_agent = $NavigationAgent2D
home_position = self.global_position
nav_agent.path_desired_distance = 4
nav_agent.target_desired_distance = 4
func _physics_process(_delta):
if nav_agent.is_navigation_finished():
return
var axis = to_local(nav_agent.get_next_path_position()).normalized()
velocity = axis * speed
move_and_slide()
func recalculate_path():
if target:
nav_agent.target_position = target.global_position
else:
nav_agent.target_position = home_position
func _on_recalculate_timer_timeout():
recalculate_path()
@@cashewolddew I see. I've dug into the problem a bit deeper and... looks like one can totally make Navigation work with just a navigation layer, however you won't be able to use layered tilemaps, which is obviously unacceptable. So only single layered tilemaps are supported without baking... too bad. Which is, incidentally, what you've already written in the video description, I should have been more attentive :)
@@Korn1holio No worries! You did great by writing about it. If there are better or more ways to do things I'm really happy to find out about them.
@@cashewolddew thanks! Yes, I am looking for more ways to do it, since the approach with NavRegion2D, while definitely working, looks a bit too 'manual' or complex to implement for procedurally generated or streamed tilemaps. Will post any updates.
I think I am a bit lost. I thought you could do all the navigation in the tilemap instead of needing that additional region node to make it all come together. Is that incorrect?
I thought the same thing, especially since a Tilemap has navigation layers. However, when I tried to do exactly that I stumbled upon a lot of troubles.
This was actually the reason I made this video. I tried so hard to make things work that I didn't want anyone to go through that again :D
I added some notes in the description regarding those issues and some discussion on Github. I'm actively checking this and if I find that an issue is fixed or that I was not doing something properly, I'll make sure to come with an update!
Wow. So what do those navigation layers do in the tile map..?
@@cashewolddew I am working on something now and the stars aligned. I am using the tilemap with nav layers and it is working! If you want it, I can share. LMK.
@@JuddGledhill I'd be really interested to know. Please write to me on any of my social media!
Thanks!
@@JuddGledhill I'd also be interested. Was attempting to learn and use the navigation layers, struggled a bit, learned Godot 4.2 added some changes, and am now in a rabbit hole lol.
This video is great, btw. Thank you.
For some reason Godot 4 doesn't work with my Nvidia graphics card. Do any of these features not exist in versions before 4.0
If I remember well, tilemap layers were not a thing in godot 3.x. This would probably imply that the navigation baking for the tilemap does not work as well, as there would be no concept of 'layer 0' without layers.
I hope you get the Nvidia graphics problems fixed. I'm not sure if it would help, but try checking that you also have the latest drivers for your graphics card.
Try updating your drivers, that worked for me atleast
My baking does not always bake close enough.
Hello! Sorry for missing your comment. What do you mean by that? Is the generated region too small? Try checking if making the navigation polygon larger would help.
@cashewolddew yes yes the generated region is always smaller than the area I selected. But I got it now thanks.
Bro make your video fast😂 (7-13m)
It’s too long
(IT will be so helpful if u make shot videos thank you)
❤
Thank you for the feedback! I am looking to condense the videos a little in the future in order to have them be easier to watch.