예제 #1
0
        private void SetHorizontalMovementAloof()
        {
            // Map raw movement vector into our 2D movement space:
            if (HorizontalMovement.Y > 0.0f) // Positive Y is special because we can move faster in that direction.
            {
                double rawMovementTheta    = Math.Atan2(HorizontalMovement.Y, HorizontalMovement.X);
                float  maxRadius           = (float)(GetMaxFwdMoveLength(rawMovementTheta));
                float  totalMovementLength = HorizontalMovement.Length() * maxRadius;
                // Clamp the movement:
                Controller.HorizontalMotionConstraint.SpeedScale = 0.5f * Math.Min(maxRadius, totalMovementLength);
            }
            else
            {
                // Clamp the movement:
                Controller.HorizontalMotionConstraint.SpeedScale = 0.5f * Math.Min(1.0f, HorizontalMovement.Length());
            }

            Controller.HorizontalMotionConstraint.MovementDirection = BepuConverter.Convert(HorizontalMovement);
        }
예제 #2
0
        private void CommitOrientationAndMovement()
        {
            if (mState == ControllerState.InputDisabled)
            {
                Controller.HorizontalMotionConstraint.SpeedScale        = 0.0f;
                Controller.HorizontalMotionConstraint.MovementDirection = BEPUutilities.Vector2.UnitY;
                return;
            }

            float diffAngle = (float)(SpaceUtils.GetQuaternionAngle(OrientationChange));

            if (diffAngle > MaxTurnAnglePerTick)
            {
                OrientationChange  = Quaternion.Slerp(Quaternion.Identity, OrientationChange, MaxTurnAnglePerTick / diffAngle);
                HorizontalMovement = Vector2.Zero; // We spent our movement turning (but this won't affect boosting.)
            }

            Controller.ViewDirection = BEPUutilities.Quaternion.Transform(Controller.ViewDirection, BepuConverter.Convert(OrientationChange));
            OrientationChange        = Quaternion.Identity;

            if (mState == ControllerState.Boosting)
            {
                Controller.HorizontalMotionConstraint.SpeedScale        = 1.0f;
                Controller.HorizontalMotionConstraint.MovementDirection = BEPUutilities.Vector2.UnitY;
            }
            else
            {
                if (AimCheck())
                {
                    Controller.HorizontalMotionConstraint.SpeedScale        = 0.375f * Math.Min(1.0f, HorizontalMovement.Length());
                    Controller.HorizontalMotionConstraint.MovementDirection = BepuConverter.Convert(HorizontalMovement);
                }
                else
                {
                    SetHorizontalMovementAloof();
                }
            }
        }