I’m sorry if my answer was confusing. I forgot about that drop-down selection and I thought you were trying to use AStar2D alongside NavigationAgent. Even though there’s a drop-down selection, it uses an A* algorithm by default and can’t be changed. It seems like they might have intended to add more than one algorithm in the future? NavigationAgent2D/3D does use an A* algorithm internally, but it’s separate from the AStar2D and AStar3D classes. I’ll edit my answer to change the wording a bit.
Also, after reading my answer again, I realise now that it sounds like I was saying there is no way to use NavigationAgent for your project, but that is not what I meant. I neglected to mention that it would also be perfectly possible to use a NavigationAgent2D for your project instead of AStar2D, depending on what you need. I simply wanted to use my own project as an emphasis that they are two separate things, and to give you something concrete to compare your own project.
If you wish to use NavigationAgent2D instead, since it already uses A*, you can follow the same principle of navigating towards each point individually.
Personally, I decided not to use NavigationAgent because it can’t really handle flying or swimming movement, and is mostly restricted to moving along the floor.
Since I only needed my drone to be able fly through doors while I let it handle its movement on its own inside rooms, it was simpler to use AStar3D. But NavigationAgent might or might not be the more appropriate solution for you.
In either case, the principle is the same; create a point map/navmesh, set a target, create a path to that target, and move towards each point in order until the final position is reached. Recalculate a new path as needed, either when you reach the destination, or when the target has moved.
Without going into too much detail, it would look a bit like this:
Add a NavigationRegion to your level, and bake the navigation mesh according to your level geometry. This can be done in the editor, or using NavigationRegion2D.bake_navigation_mesh().
By default, your level geometry has to be children of the NavigationRegion, but this can be changed in geometry_source_geometry_mode to use groups instead
Add a NavigationAgent2D to your car. It will automatically use the navigation mesh you created with NavigationRegion, unless you created more than one, in which case you need to tell it which one to use with NavigationAgent2D.set_navigation_map()
Set the car’s target (e.g.: a finish line, or another vehicle which your car is trying to ram into, etc.) in NavigationAgent2D.target_position. This automatically creates a new navigation path inside NavigationServer.
Every frame, call NavigationAgent2D.get_next_path_position(). This returns a Vector3 coordinate which you can plug into your car’s movement function.
e.g.: my_car.move_to(navigationagent.get_next_path_position())
When your car is within the distance set in path_desired_distance, the next path position will automatically be updated the next time your call get_next_path_position().
Then check if NavigationAgent2D.is_navigation_finished() to see if your car has reached the last point in the path.
One thing of note is to not set NavigationAgent2D.target_position every frame, especially if you have many NavigationAgents, since it recalculates the path every time you do, which is costly. If you’re trying to follow a moving target, you can set a timer and update the target_position only as often as you need, each second or so for example, or alternatively you can check if the moving target has moved away far enough from target_position.