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;
83 _state.
Velocity.LengthSquared() < StopEpsilon * StopEpsilon)
84 _state.Velocity = Vector2.Zero;
88 var newPos = pos + _state.Velocity * dt;
93 if (_coords is
null || _sceneLayer is
null)
94 throw new InvalidOperationException(
"Grid wrapping requires coordinates/layer.");
96 var wrapped = _coords.FindEquivalentSceneLayerCoordinates(
97 new PointF(newPos.X, newPos.Y),
98 _sceneLayer.GridColumnCount - 1,
99 _sceneLayer.GridRowCount - 1);
101 float newX = newPos.X;
102 float newY = newPos.Y;
110 newPos =
new Vector2(newX, newY);
124 internal void ZeroVelocityComponent(
bool zeroX,
bool zeroY)
126 if (!zeroX && !zeroY)
129 var v = _state.Velocity;
130 _state.Velocity =
new Vector2(zeroX ? 0f : v.X, zeroY ? 0f : v.Y);
139 private void ClampVelocity()
141 if (_state.MaxSpeed is
null)
144 var v = _state.Velocity;
145 var speed = v.Length();
146 var max = _state.MaxSpeed.Value;
148 if (max > 0 && speed > max)
149 _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
Non-negative linear damping coefficient per second (0 = no damping). During integrated movement,...
readonly bool HasMotion
Gets a value indicating whether the object is in motion.