19 _state.Velocity = velocity;
30 _state.Acceleration = acceleration;
40 _state.MaxSpeed = maxSpeed;
51 _state.LinearDamping = MathF.Max(0f, dampingPerSec);
54 private bool AdvanceIntegrated(
float dt)
69 private void Step(
float dt)
72 _state.Velocity += _state.Acceleration * dt;
80 const float StopEpsilon = 0.01f;
82 _state.
Velocity.LengthSquared() < StopEpsilon * StopEpsilon)
83 _state.Velocity = Vector2.Zero;
87 var newPos = pos + _state.Velocity * dt;
92 if (_coords is
null || _sceneLayer is
null)
93 throw new InvalidOperationException(
"Grid wrapping requires coordinates/layer.");
95 var wrapped = _coords.FindEquivalentSceneLayerCoordinates(
96 new PointF(newPos.X, newPos.Y),
97 _sceneLayer.GridColumnCount - 1, _sceneLayer.GridRowCount - 1);
99 float newX = newPos.X;
100 float newY = newPos.Y;
108 newPos =
new Vector2(newX, newY);
122 internal void ZeroVelocityComponent(
bool zeroX,
bool zeroY)
124 if (!zeroX && !zeroY)
127 var v = _state.Velocity;
128 _state.Velocity =
new Vector2(zeroX ? 0f : v.X, zeroY ? 0f : v.Y);
137 private void ClampVelocity()
139 if (_state.MaxSpeed is
null)
142 var v = _state.Velocity;
143 var speed = v.Length();
144 var max = _state.MaxSpeed.Value;
146 if (max > 0 && speed > max)
147 _state.Velocity = v * (max / speed);
Central controller responsible for managing all movement modes for a single IMovable object....
bool WrapX
Enables or disables horizontal world wrapping. When enabled, movement crossing the left/right edges w...
bool WrapY
Enables or disables vertical world wrapping. When enabled, movement crossing the top/bottom edges wra...
void SetMaxSpeed(float? maxSpeed)
Sets the maximum speed for the current state. Only applies to integrated movement.
void CancelScript()
Cancels any active scripted movement and clears the current script state. Raises ScriptedMovementStop...
void SetLinearDamping(float dampingPerSec)
Sets the linear damping value, which determines the rate at which linear motion is reduced over time.
void SetAcceleration(Vector2 acceleration)
Sets the acceleration of the object.
void SetVelocity(Vector2 velocity)
Sets the velocity of the object.
Vector2 GetPosition()
Get the current position in the mover's PositionSpace.
void SetPosition(Vector2 pos)
Set the position in the mover's PositionSpace.
MovementSpace PositionSpace
Which unit system this mover uses for its position.
MovementSpace
Specifies the coordinate system used for movement calculations and updates.
Vector2 Velocity
Velocity in current MotionSpace units per second.
Vector2 Acceleration
Acceleration in current MotionSpace units per second^2.
float LinearDamping
Linear damping per second in [0..1]. 0 = no damping. Apply as v *= (1 - LinearDamping * dt) in the co...
readonly bool HasMotion
Gets a value indicating whether the object is in motion.