Pathfinding

The Pathfinding extension provides a behavior that will allow your objects to avoid obstacles.
Pathfinding is not able to avoid obstacles that have moved after the object starts moving on its computed path.
To compute a path, GDevelop will use a virtual grid. You can set the size of this grid when editing an object with the behavior.

The algorithm used to compute the path is called A* : https://en.wikipedia.org/wiki/A*_search_algorithm

Using the behavior

Add the behavior to objects that will be moved, and to the objects that will act as obstacles. You can then use the action “Go to a position” to move an object that will avoid obstacles.

As said before, you can change the virtual grid size to adapt it to the size of your objects. You can also change the speed of objects by using actions.

If your objects are bigger than the grid size, they can collide with obstacles when moving on their path. To avoid this, you can add “extra borders” to the obstacle when editing the behavior. For example, on this picture, the cells that are grayed represent the area that the “pea” cannot cross :

However, the pea can collide with the obstacle.
To avoid this, you can add one extra cell at the top, right, bottom and left of the obstacle. Then, the pea will properly avoid the obstacle :

Advanced functions

A path computed by the behavior is internally represented as a succession of “nodes”. The object will thus go from node to node.
Expressions are available to get the X/Y position of the previous node or next node, so you can, for example, turn the object according to its movement.


Each point represents a node