Prevent agents from moving backward on a navigation mesh

Godot Version

4.2.2

Question

Hello.

I’m an experienced programmer but i have no idea about making games. Im trying to make a game for my friend as a gift, so i does not need to be high quality, follow all the best practices etc.

I have main lobby with few minigames one of which is a clone of packman with some customizations. I have my own map with tileset that defines navigation mesh for ghosts. The problem is that i want ghosts to move one way only - none of the ghosts should be able to turn 180 degree in place.

I was able to achieve that for one ghost by updating the tile map every 0.1 sek. The ghost is checking its position and velocity and remove the tile behind him, forcing navigationAgent2D to find a path that will move him forward (photo attached).
obraz

The problem is that with this solution every ghost should have its own tilemap with navigation mesh (so they will not break each other paths). When I added second tilemap it broke the existing one - the ghost get stuck every time on corners. I tried setting each navigation tilemap on separate navigation layer, telling navigationAgent explicity which map should he use but no luck.

Is there a better way to achieve such behavior? Thanks in advance for any suggestions and ideas.

I think for such a simple grid-based pathfinding you do better running a basic custom graph to search for cell paths.

The NavigationAgent and NavigationServer are for navigation mesh surface based pathfinding. The “restrictions” that you mentioned here for your project make no sense in the context of a navigation mesh. By design the entire connected surface is both traversable and usable, not just “its center” and not just “one direction”.

While you can use AStar2D or AStarGrid2D for waypoints, everything the engine can provide is complete overengineered for a “pac man” type game, even the AStar classes. With a waypoint system you can disconnect points or increase their costs so much that your actors go the other “one-way” but that will cover only one of your ghost so you would need to make copies for every ghost.

Better look at basic pathfinding tutorials like those from redblob, that works far better for a “pac-man” style game.

1 Like

Thanks for such detailed response. I will definietly check the tutorial!