+3 votes

When working with grid based path finding in Godot how do you normally handle different agent types? In the game I am working on I have a regular agent, and one that occupies 2 cells on the grid, and one that can fly. The idea I have now is to use a separate AStar object to store the grid for each type. The height is max 4 units so I can use AStar for flying as well.

This keeps it possible to add new actor types as well but is it waste of memory? Also how to deal with avoiding nodes occupied by other agents? The game is turn based so I don’t want to do any object avoiding type thing. Is there a simple way to mark a node in the AStar as temporarily unwalkable?

in Engine by (23 points)

2 Answers

0 votes

Create a dictionary to record infos for each tile. When tile is occpied, update this in the dictionary.
When using AStar, add tiles that has occupied == false.
Or if you want to keep the original added tiles in AStar, disconnect the tiles and their neighboring tiles when their methods OCCUPY() is called and reconnect them when "occupied" is turnd to false.

by (809 points)
0 votes

As to avoiding nodes occupied by other agents or making all the air points inaccessible with AStar there's a method for it.

void set_point_disabled(id: int, disabled: bool = true)

Disables or enables the specified point for pathfinding. Useful for making a temporary obstacle.

It seems to me that it might be OK to have different instances of AStar for types of movement like flying or walking, so you won't have to disable and reenable too many points

by (24 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.