Script Reference

MovementMotor.cs

Authoritative tile movement component for units. It requests paths, consumes tile steps on ticks, supports running, and queues visual move segments.

CoreMovementSimulation

Overview

MovementMotor owns the actual gameplay position of a unit. It stores the current tile, follows active paths, processes movement on ticks, and generates VisualMoveSegment data for the view layer.

Use this component when a unit needs to move on the tile grid. Pair it with UnitViewMotor when you want smooth visual movement.

Inspector Settings

Path Service Behaviour

MonoBehaviour assigned as the pathfinding provider. It must implement IPathService, such as TilePathService.

Start Running

If enabled, the unit begins in running mode and can consume two tiles per tick instead of one.

Public API

InitializeAtCurrentTransform()

Snaps the motor's current tile state to the object's current transform position.

SetPathService(MonoBehaviour serviceBehaviour)

Assigns the pathfinding service used by this motor.

TryMoveTo(TileCoord destinationTile)

Requests a path to a tile destination. Returns false if the destination is invalid, no path service exists, or no path is found.

TryMoveToWorld(Vector3 worldPosition)

Converts a world position to a tile through GridManager, then requests movement to that tile.

CancelMovement()

Clears the active path and pending visual segments.

SnapToTile(TileCoord tile)

Immediately moves the unit's authoritative tile and transform position to the specified tile.

SetRunning(bool running)

Sets whether the unit is walking or running.

ToggleRunning()

Switches between walking and running mode.

ProcessMovementTick(long tick)

Processes movement for one simulation tick. Usually called by a tick listener or controller, not by random gameplay scripts.

Runtime Properties

CurrentTileThe unit's authoritative tile.
PreviousTileThe last tile before the most recent committed step.
NextStepTileThe next tile in the current path, if any.
IsMovingTrue while the motor has an active path.
IsRunningTrue when running mode is enabled.
ActivePathRead-only view of the remaining path.
VisualSegmentQueueCountNumber of visual movement segments waiting to be consumed.

Common Usage

// Move to a known tile.
movementMotor.TryMoveTo(destinationTile);

// Move to a clicked world position.
movementMotor.TryMoveToWorld(hit.point);

// Toggle walk/run.
movementMotor.ToggleRunning();
Walking vs Running: Walking consumes one tile per tick. Running consumes up to two tiles per tick.