person-walkingMovement Agents/NPCs

Use Movement_Agent to move entities with pathfinding and navmesh constraints.

Movement Agents

Movement_Agent is a movement helper component used for steering and pathfinding.

Most commonly, you use it to:

  • Request a path toward a target (set_path_target)

  • Constrain an entity to walkable space (lock to a Navmesh)

circle-info

This page covers movement and pathfinding. For building/querying navmeshes, see Navmesh & Collision.

Movement_Agent API reference

Movement_Agent :: class : Component {
    Set_Path_Target_Result :: struct {
        success:        bool;
        next_point:     v2;
        move_direction: v2;
    }

    // Request a path toward target at a given speed.
    set_path_target :: method(target: v2, speed: float) -> Set_Path_Target_Result;

    // Constrain this agent to a navmesh (snap to it every frame).
    // Pass null to clear.
    set_navmesh_to_lock_to :: method(navmesh: Navmesh);

    // Common tuning/state
    movement_speed:   float;
    friction:         float;
    velocity:         v2;
    input_this_frame: v2;
}
circle-exclamation

Pathfinding (set a target)

Call set_path_target every frame (or whenever your target changes).

circle-info

set_path_target is processed later in the frame in parallel with other agents, so the first frame you set a new target may not return success == true.

Lock movement to a navmesh (stay on walkable space)

If an entity should never leave walkable space, lock it to a navmesh:

Call it with null to clear.

Creating Moving NPCs

This is a minimal “follow the player” NPC using a movement agent:

Last updated