Skip to content

# Path Finding Movement

A path finding movement is a particular path movement where the path is calculated to reach a target. The target is a map entity (by default the hero).

The movement calculates repeatedly the shortest path towards the target entity, taking into account obstacles of the map. With this type of movement, an entity is capable of finding its way in a maze.

Note

This type of movement computes a precise path on the map grid and avoids complex obstacles by using a sophisticated A.I. algorithm (A*).

If you just need to go straight towards a target, which may be more natural for basic enemies, see the target movement type.

## Methods Inherited from `movement`

Path finding movements are particular movement objects. Therefore, they inherit all methods from the type movement.

See movement to know these methods.

## Methods of the type `path_finding_movement`

The following methods are specific to path finding movements.

### `path_finding_movement:set_target(entity)`

Sets the target entity of this movement.

`entity` (entity)
  The entity to target.

### `path_finding_movement:get_speed()`

Returns the speed of this movement.

Return value (number)
  The speed in pixels per second.

### `path_finding_movement:set_speed(speed)`

Sets the speed of this movement.

`speed` (number)
  The new speed in pixels per second.

### `path_finding_movement:get_angle()`

Returns the angle of the current trajectory in radians.

East is `0`, North is `math.pi / 2`, West is `math.pi`, South is `3 * math.pi / 2`.

Return value (number)
  The angle in radians.

Note

If you prefer a value in a 4-direction system, see `movement:get_direction4()`.

## Events Inherited from `movement`

Path finding movements are particular movement objects. Therefore, they inherit all events from the type movement.

See movement to know these events.

April 1, 2025