**This is an old revision of the document!**

Pathfinding

Pathfinding behavior allows us to move objects to a selected destination as well as to flag items as obstacles that are going to be avoided by the moving objects.

Examples

Add behaviour to object

To add behavior to an object, first open the object's properties by right clicking on the scene object. Select “Edit object” from the popup list. (You can also select the object from the Objects menu.)

Now, select the behavior tab and click the “add behavior” button.

Next, we have two options to choose from:

Option 1: Pathfinding behavior

Pathfinding behavior allow us to move the object to a destination while it is going to avoid all objects flagged as obstacle.

After we add the behaviour to the object, we can customize number of options

  • acceleration: this is how fast our object going to accelerate while moving on a path
  • allow diagonals: is the object can move in diagonals or not
  • angle offset: in case our sprite facing the wrong direction we can set the angle offset
  • extra border size: border size around the object to set how close the object can move to the obstacles
  • max speed: maximum speed the object can move on the path
  • rotate object: disable if you don't want the object to rotate while moving on the path
  • rotate speed: speed of rotation
  • virtual cell height and width: our path is generated using a virtual grid, we can change the size of the cells here, the smaller the size is, the smoother the movement is going to be. A smaller size implies more calculations so try to still keep a size as large as possible.

PathfindingObstacle behavior

By using the pathfinding obstacle behavior we can flag any object to be an obstacle. After we add the behavior to the object we have two options to customize:

  • impassable: if we enable this the obstacle is going to be impassable and the moving object is going to avoid it at all cost.
  • cost: in case the obstacle is not impassable, we can set a cost for the obstacle. The moving object, when looking for the best possible path to a destination, is going to prefer to avoid the obstacle with high cost values. For example, a river might have some cost so that the moving object is going to avoid it if possible, but in case there is no other way around the river, or if the river has a lower cost compared to another area, the moving object will go through it (instead of climbing a mountain with a higher cost for example). And if we put crocodiles into the river and increase its cost, the moving object might decide to climb the mountains instead.