Godot Version
4.2.1
Question
In this game I am making, I want the enemies to chase the player around the walls and obstacles. The enemies use a NavigationAgent2D, and the scene has a TileMap and a NavigationRegion2D.
TileMap
I added a navigation layer to the TileMap so the enemies properly pathfind around the TileMap walls to get to the player
Obstacles
For testing purposes, I manually excluded the Hole from the NavigationPolygon. My ultimate goal is to exclude the different obstacles with code. I saw an example in the Godot 4.0 documentation here
I am using 4.2, and even if the make_polygons_from_outlines
function is now deprecated, I’m guessing it is still possible to do.
Code
This is the code that the enemies use to move
if(isChasing):
var direction = nav_agent.get_next_path_position() - global_position
direction = direction.normalized()
velocity = direction * SPEED
Problems
I’m creating this topic because I’m having a hard time debugging the weird paths that are created for the enemies when they are chasing the player.
I haven’t figured out why the enemies keep going straight through the hole even thought it is not part of the NavigationPolygon
And sometimes, the enemies will have this very weird path around TileMap walls.
Of course the enemy has collision with that wall so it doesn’t work, but the path is still created that way, and then it often changes to a good path around. FYI, my code sets the
nav_agent.target_position
to player.global_position
every .5 seconds if the enemy is in chasing mode. This might be why some paths are weird?
Here are a few more screenshots to help