Exemple #1
0
        public void Update(float frameTime, MovementInput input)
        {
            Forward   += (input.Forward ? Acceleration : Deceleration) * frameTime;
            Backward  += (input.Backward ? Acceleration : Deceleration) * frameTime;
            Leftward  += (input.Leftward ? Acceleration : Deceleration) * frameTime;
            Rightward += (input.Rightward ? Acceleration : Deceleration) * frameTime;
            Upward    += (input.Upward ? Acceleration : Deceleration) * frameTime;
            Downward  += (input.Downward ? Acceleration : Deceleration) * frameTime;

            var maxVelocity = Constants.MaxVelocity;

            if (input.Sprint)
            {
                maxVelocity *= 3;
            }

            Forward   = Forward.Clamp(0.0f, maxVelocity);
            Backward  = Backward.Clamp(0.0f, maxVelocity);
            Leftward  = Leftward.Clamp(0.0f, maxVelocity);
            Rightward = Rightward.Clamp(0.0f, maxVelocity);
            Upward    = Upward.Clamp(0.0f, maxVelocity);
            Downward  = Downward.Clamp(0.0f, maxVelocity);
        }