Function MovementUtilities.ClampVelocity

ClampVelocity (Vector2 velocity, float maxSpeed, float speedLimitFactor, bool slowWhenNotFacingTarget, bool preventMovingBackwards, Vector2 forward)

Clamps the velocity to the max speed and optionally the forwards direction.

Public Static
Vector2 ClampVelocity (

Vector2

velocity

Desired velocity of the character. In world units per second.

float

maxSpeed

Max speed of the character. In world units per second.

float

speedLimitFactor

Value between 0 and 1 which determines how much slower the character should move than normal. Normally 1 but should go to 0 when the character approaches the end of the path.

bool

slowWhenNotFacingTarget

Slow the character down if the desired velocity is not in the same direction as the forward vector.

bool

preventMovingBackwards

Prevent the velocity from being too far away from the forward direction of the character.

Vector2

forward

Forward direction of the character. Used together with the slowWhenNotFacingTarget parameter.

)

Clamps the velocity to the max speed and optionally the forwards direction.

Note that all vectors are 2D vectors, not 3D vectors.

Return

The clamped velocity in world units per second.