UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Component Module / Movement Component Completed

Component Module — UGTK

Movement Component

Summary

The Movement Component moves an object in a direction at a speed, and raises events when it starts and stops moving. On top of it two variants add a boundary: one clamped to explicit min/max coordinates, one clamped to the bounds of a Collider.

It is the base every other movement in the Component Module builds on — Follow, PingPong, Dash — so the speed, the direction and the start/stop events are the same everywhere.


Content


Modules Dependencies


Setup

Add the MovementComponent prefab as a child of the object to move:

Configure speed and direction:

For a bounded movement use one of the two limited prefabs instead — CoordinatesMovementComponent (Mn_CoordinatesMovementComponent) or SurfaceMovementComponent (Mn_SurfaceMovementComponent):

Configure the limits — the six coordinates, or the collider that defines the allowed area:


How To Use

movementComponent.SetSpeed(10f);
float speed = movementComponent.GetSpeed();
movementComponent.SetDirection(Vector3.right);
movementComponent.IncreaseSpeed(5f);
movementComponent.DecreaseSpeed(3f);

Events, all wirable from the inspector:

Event Raised when
OnSpeedChange(float) the speed changes, with the new value
OnDirectionChange(Vector3) the direction changes, with the new vector
OnStartMoving the object goes from still to moving
OnStopMoving the object comes to a stop

Good to know:


Limits

Variant Bound by Use it for
Mn_CoordinatesMovementComponent six values: min/max on X, Y and Z a rectangular play area, a rail, a camera clamp
Mn_SurfaceMovementComponent the bounds of a Collider an arbitrary area you can draw and move in the scene

Both clamp after the movement, every frame, so the object stops flush against the limit.

Mn_SurfaceMovementComponent clamps to the collider's bounding box, not to its actual shape: with a sphere or a mesh collider the allowed area is the box that contains it, not the silhouette. A missing collider logs an error every frame.


Testing Scene

Open Debug/MovementScene.unity and press Play: the objects move, and the limited ones stop at their boundary. Speed and direction can be changed in Play Mode to see the events fire.


Technical Info

Path Content
Scripts/Mn_MovementComponent.cs The base: speed, direction, Move(), the four events and the IPausable implementation
Scripts/LimitedMovements/Mn_LimitedMovementComponent.cs Abstract base that applies a limit after each move
Scripts/LimitedMovements/Mn_CoordinatesMovementComponent.cs Clamp on explicit min/max X, Y, Z
Scripts/LimitedMovements/Mn_SurfaceMovementComponent.cs Clamp on a collider's bounds, plus SetMovementBoundsCollider
Prefabs/*.prefab The three ready-made components
Debug/MovementScene.unity Test scene

© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 5 modules in total.