TTP: How does Godot 4 handle Navigation?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to the point in this video we'll talk about the new navigation system being developed in godot 4. you'll notice that it's a little bit different from the old one and because of that several of the classes were changed and by classes i mean nodes and resources and here you are seeing a timelapse of me setting up a csg scene with some ground some obstacles and also including a static body around each object so just to make sure everything is included in the navigation code to the left you can see the godot 4 is the new one to the right it's the old godot 3.3 and in both cases to set up a player you can use kinematic body as usually is used or no 3d or spatial in the old godot or also rigid body all cases can be used in both and finally we set up the navigation itself and here's where you'll notice the differences on the old google 3.3 you set up a navigation instance inside it you use a navigation mesh you use the navigation mesh to bake a navigation mesh around your scene which means that your scene needs to be a child of that navigation itself and finally you put your player inside the navigation or have your player have a reference to that navigation to be able to calculate the path but for godot 4 you will have a navigation region which is a little bit different you include the navigation region node in your scene also put your map underneath that navigation region so that it can bake the navigation mesh but instead of having a navigation mesh child of that node the navigation mesh is now a resource within navigation region node so you just click new new navigation mesh and finally bake the navigation mesh as you would with a navigation mesh of the old kudu 3.3 and with all that other way you can see here me struggling to implement all the the cases both for the new and the old navigations all code you're seeing here you'll find in the description below including the reference that i took to be able to implement the code you're seeing for goto for of course the code depends on how you yourself implement but comparing my two codes you'll notice that in my ready function i needed to set up a map which is supposed to be solved by the time when godot 4 is released but for now this manual process needs to be done for it to work also in the physics process of course i'm just implementing something very simple here but you'll notice that on the old version you need to get the entire path at once and then you navigate through this path array to be able to go from waypoint to waypoint within your navigation mesh in the new one you just get the next location with agent dot get next location something new that you'll notice is that the new good old four player does not have a reference to the navigation itself instead it uses something called navigation agent which means that the player does not need to be remotely nearby the navigation region and this is the main advantage of the new implementation because now you'll be able to have multiple navigation regions maybe you have like a very complex map in a grid map for example each separate area can be its own navigation region navigation regions can actually move around and even with multiple navigation regions moving around compared to each other the navigation agent is something static within the player and the navigation agent itself is able to calculate the next location as you can see in line 26 which means that you don't need to take care of the entire path array though you can if you really want to another difference is as you can see instead of just moving and sliding from within the physics process i actually set velocity at line 31 and the navigation agent itself calls a signal velocity computed and its result is the actual next step for you to escape all the colliding object you can also have moving objects and within it you can instantiate the new node called navigation static bodies which is used once again in the navigation agent's collision detection within the set velocity and finally there's another callback or another signal of target reached for whenever the player actually reaches that target which means you don't need to do it manually anymore some extra notes about this new implementation is that i don't know how the old one worked but the new one is using a library called recast and detour or more specifically only the recast part of that library which is used by many other game engines and also other programs to create the navigation mesh itself so bake the navigation polygon from collision objects and from there godot uses an a-star algorithm to calculate the path it is unfortunate that the current implementation is not using the detour part which includes dynamic pathfinding and other advantages over just pure a-star but let's see who knows maybe in the future but for now you can look at this very nice plugin which actually implements recast and detour at the same time you can see that the the plugin is a little bit old now because the developer is not updating for a while but give him some love if if like me you'd like to have more intelligent navigation systems within google thank you for watching
Info
Channel: Aknakos
Views: 2,717
Rating: undefined out of 5
Keywords: Godot4
Id: 1c26NezEhmQ
Channel Id: undefined
Length: 6min 1sec (361 seconds)
Published: Sun May 30 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.