Documentation
¶
Overview ¶
Package motion executes paths over time: spline interpolation, speed/easing curves, per-entity motion stacks (current + queued + idle fallback), pause/resume/abort.
Distinct from kit/pathfinding which produces a path (waypoint sequence); motion is the per-tick execution of that path through space, with a built-in motion-type registry (Point, Path, Idle).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrEmptyStack = errors.New("motion: stack is empty")
)
Errors surfaced by the Stack.
Functions ¶
This section is empty.
Types ¶
type IdleMotion ¶
type IdleMotion struct{}
IdleMotion holds the entity in place. Never reports done. Useful as the Stack.idle fallback.
func (IdleMotion) OnAbort ¶
func (IdleMotion) OnAbort()
func (IdleMotion) OnPause ¶
func (IdleMotion) OnPause()
OnPause / OnResume / OnAbort default no-ops.
func (IdleMotion) OnResume ¶
func (IdleMotion) OnResume()
type Motion ¶
type Motion interface {
// Kind is a stable identifier for logs and factory wiring.
Kind() string
// Tick advances the motion by dt. `current` is the entity's
// transform at the start of the tick — implementations may use it
// as the "from" for interpolation (Point) or ignore it (Path).
Tick(dt time.Duration, current Transform) (next Transform, done bool)
// OnPause / OnResume / OnAbort fire when the stack transitions
// states. Default implementations are no-ops; override when state
// needs invalidation (e.g. abort cancels a pending callback).
OnPause()
OnResume()
OnAbort()
}
Motion is the unit of executable movement. Tick is called every frame; it advances internal state by `dt` and reports the next Transform plus whether the motion has completed.
Implementations should be cheap: a Motion typically lives for many ticks and Tick runs at the simulation frequency.
type PathMotion ¶
type PathMotion struct {
Waypoints []geometry.Vec3
Speed float32
Arrival float32
// contains filtered or unexported fields
}
PathMotion walks through a list of waypoints in order at a constant speed. Done when the last waypoint is reached.
func NewPath ¶
func NewPath(points []geometry.Vec3, speed float32) *PathMotion
NewPath constructs a PathMotion with a 0.05-unit default arrival.
func (PathMotion) OnAbort ¶
func (PathMotion) OnAbort()
func (PathMotion) OnPause ¶
func (PathMotion) OnPause()
OnPause / OnResume / OnAbort default no-ops.
func (PathMotion) OnResume ¶
func (PathMotion) OnResume()
type PointMotion ¶
type PointMotion struct {
Target geometry.Vec3
Speed float32 // world-units per second
ArrivalThreshold float32 // distance below which the motion completes
}
PointMotion drives the entity toward a fixed point at a constant speed. Done when within a configurable arrival threshold.
func NewPoint ¶
func NewPoint(target geometry.Vec3, speed float32) *PointMotion
NewPoint constructs a PointMotion with a 0.05-unit default arrival.
func (PointMotion) OnAbort ¶
func (PointMotion) OnAbort()
func (PointMotion) OnPause ¶
func (PointMotion) OnPause()
OnPause / OnResume / OnAbort default no-ops.
func (PointMotion) OnResume ¶
func (PointMotion) OnResume()
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack is a per-entity motion stack: a current Motion, a queue of follow-ups, and an optional idle Motion that runs when the queue drains. Goroutine-safe; the typical owner is the entity actor.
func (*Stack) Push ¶
Push adds m to the queue. If nothing is currently active, m is promoted immediately to current.
func (*Stack) Replace ¶
Replace aborts the current motion (and clears the queue) and installs m as the new current. Useful for "drop everything and do X" signals (player issued a new order).