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
| CurrentTile | The unit's authoritative tile. |
|---|---|
| PreviousTile | The last tile before the most recent committed step. |
| NextStepTile | The next tile in the current path, if any. |
| IsMoving | True while the motor has an active path. |
| IsRunning | True when running mode is enabled. |
| ActivePath | Read-only view of the remaining path. |
| VisualSegmentQueueCount | Number 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();