1.10.04 - Path movement

A path movement follows a specified path on an 8*8 pixels grid, in an 8-direction system. A path is a succession of steps of 8 pixels in one of the 8 main directions. You can define each step of the path and make it repeated if you want.

Methods inherited from movement

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

See Methods of all movement types to know these methods.

Methods of the type path movement

The following methods are specific to path movements.

path_movement:get_path()

Returns the path of this movement.

path_movement:set_path(path)

Sets the path of this movement.

Example of use:

-- Example of code from a map script.
-- Assume that there is an NPC called "scared_cat" on this map.
function scared_cat:on_interaction()
  -- The hero is talking to me: run away!
  sol.audio.play_sound("meow")
  local movement = sol.movement.create("path")
  -- This path is arbitrary, it's just an example (North and then West).
  movement:set_path{2,2,2,2,2,2,4,4,4,4}
  movement:set_speed(80)
  self:start_movement(movement)
end

path_movement:get_speed()

Returns the speed of this movement.

path_movement:set_speed(speed)

Sets the speed of this movement.

path_movement:get_loop()

Returns whether this movement repeats itself once the end of the path is reached.

path_movement:set_loop([loop])

Sets whether this movement repeats itself once the end of the path is reached.

path_movement:get_snap_to_grid()

Returns whether this movement automatically snaps to the map grid the map entity that it controls.

The map grid is composed of squares of 8*8 pixels. All tiles are aligned to the grid. This property has no effect if there is no current map of if this movement is not attached to a map entity.

path_movement:set_snap_to_grid([snap])

Sets whether this movement should automatically snap to the map grid the map entity that it controls.

The map grid is composed of squares of 8*8 pixels. All tiles are aligned to the grid. This property has no effect if there is no current map of if this movement is not attached to a map entity.

path_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.

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

Events inherited from movement

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

See Events of all movement types to know these events.