class

PointClickEngine::Characters::MovementController

Inherits PointClickEngine::Core::GameConstants < Reference < Object

Handles all aspects of character movement and navigation

This class centralizes movement logic that was previously duplicated across the Character class. It provides both direct movement and pathfinding capabilities with optimized calculations.

Features

  • Direct movement to target positions
  • Pathfinding with waypoint navigation
  • Automatic animation selection based on movement direction
  • Walkable area constraint checking
  • Performance optimized vector calculations

Usage

controller = MovementController.new(character)
controller.move_to(target_position)
controller.update(dt)

Constructors

new(character : Character)
Source

Instance methods

character

The character this controller manages

Source
current_path_index

Current index in the pathfinding waypoints

Source
current_path_index=(current_path_index : Int32)

Current index in the pathfinding waypoints

Source
current_speed

Get current movement speed

Source
distance_to_target

Get remaining distance to target

Source
following_path?

Check if character is following a path

Source
move_along_path(waypoints : Array(RL::Vector2))

Initiate movement along a predefined path

Sets up pathfinding movement through a series of waypoints. The character will navigate through each waypoint in sequence.

  • waypoints : Array of waypoints to follow
path = scene.find_path(start, destination)
controller.move_along_path(path) if path
Source
move_to(target : RL::Vector2, use_pathfinding : Bool | Nil = nil)

Initiate direct movement to a target position

Sets up direct movement (no pathfinding) to the specified target. Automatically selects appropriate walking animation and clears any existing pathfinding data.

  • target : World position to move to
  • use_pathfinding : Whether to use pathfinding (default: character setting)
controller.move_to(Vector2.new(200, 300))
controller.move_to(target, use_pathfinding: true)
Source
moving?

Check if character is currently moving

Source
on_movement_complete

Callback to execute when movement completes

Source
on_movement_complete=(on_movement_complete : Proc(Nil) | Nil)

Callback to execute when movement completes

Source
path

Pathfinding waypoints (nil if using direct movement)

Source
path=(path : Array(RL::Vector2) | Nil)

Pathfinding waypoints (nil if using direct movement)

Source
set_speed(speed : Float32)

Set movement speed

Source
stop_movement

Stop all movement immediately

Clears movement target, pathfinding data, and returns character to idle state. Executes completion callback if one was set.

Source
target_position

Current movement target (nil if not moving)

Source
target_position=(target_position : RL::Vector2 | Nil)

Current movement target (nil if not moving)

Source
update(dt : Float32)

Update movement state and position

Called every frame to process movement calculations and update character position. Handles both direct movement and pathfinding.

  • dt : Delta time in seconds since last update
Source