コード例 #1
0
        public VehicleDriveControls GetNextFromPlayerInput(VehicleDriveControls current, StandardPlayerInput playerInput, float deltaTime)
        {
            float axis1 = AxisValue(current.Axis1, playerInput.HorizontalInput, Axis1RateOfChange, deltaTime);
            float axis2 = AxisValue(current.Axis2, playerInput.VerticalInput, Axis2RateOfChange, deltaTime);
            float axis3 = AxisValue(current.Axis3, playerInput.RotationInput, Axis3RateOfChange, deltaTime);

            return(new VehicleDriveControls(axis1, axis2, axis3));
        }
コード例 #2
0
 public VehicleControlsConfig(float axis1RateOfChange, float axis2RateOfChange, float axis3RateOfChange, VehicleDriveControls defaultControl)
 {
     Axis1RateOfChange = axis1RateOfChange;
     Axis2RateOfChange = axis2RateOfChange;
     Axis3RateOfChange = axis3RateOfChange;
     DefaultControl    = defaultControl;
     PossibleDeltas    = GenerateDeltas(axis1RateOfChange, axis2RateOfChange, axis3RateOfChange);
 }
コード例 #3
0
        public VehicleDriveControls GetControlFromDeltas(AxisDeltas axisDeltas, VehicleDriveControls currentState, float deltaTime)
        {
            float resultingAxis1Value = AxisValue(currentState.Axis1, axisDeltas.Delta1, Axis1RateOfChange, deltaTime);
            float resultingAxis2Value = AxisValue(currentState.Axis2, axisDeltas.Delta2, Axis2RateOfChange, deltaTime);
            float resultingAxis3Value = AxisValue(currentState.Axis3, axisDeltas.Delta3, Axis3RateOfChange, deltaTime);

            return(new VehicleDriveControls(resultingAxis1Value, resultingAxis2Value, resultingAxis3Value));
        }
コード例 #4
0
 public void GetPossibleControlChanges(VehicleDriveControls currentState, float deltaTime, List <VehicleDriveControls> possibleControls)
 {
     foreach (var axisDeltas in PossibleDeltas)
     {
         VehicleDriveControls resulting = GetControlFromDeltas(axisDeltas, currentState, deltaTime);
         possibleControls.Add(resulting);
     }
 }
コード例 #5
0
        private static DynamicTransform2 ProcessVehicleDrive(DynamicTransform2 currentVehicleState, VehiclePrototype prototype, VehicleDriveControls controlState, float deltaTime)
        {
            var newDynamicTransform = prototype.VehicleDrive(currentVehicleState, controlState, deltaTime);

            //Gun recoil would go here
            return(newDynamicTransform);
        }
コード例 #6
0
 public VehicleControls(VehicleDriveControls driveControls, bool gunTriggerDown)
 {
     DriveControls  = driveControls;
     GunTriggerDown = gunTriggerDown;
 }
コード例 #7
0
 public VehicleControls(VehicleDriveControls driveControls) : this(driveControls, false)
 {
 }
コード例 #8
0
        private static DynamicTransform2 ProcessState(AsteroidsControlData data, DynamicTransform2 state, VehicleDriveControls controls, float deltaTime)
        {
            float appliedRotationalThrust;

            if (controls.Axis1 != 0f)
            {
                appliedRotationalThrust = -data.RotationAcceleration * controls.Axis1;
            }
            else
            {
                appliedRotationalThrust = -state.AngularVelocity / deltaTime;
            }
            float originalRotationalVelocity = state.AngularVelocity;
            float newRotationalVelocity      = originalRotationalVelocity + appliedRotationalThrust * deltaTime;

            if (Math.Abs(newRotationalVelocity) > data.MaxRotationSpeed)
            {
                newRotationalVelocity   = Math.Sign(newRotationalVelocity) * data.MaxRotationSpeed;
                appliedRotationalThrust = (newRotationalVelocity - originalRotationalVelocity) / deltaTime;
            }

            float               rotatedAmount               = deltaTime * originalRotationalVelocity + 0.5f * (deltaTime * deltaTime) * appliedRotationalThrust;
            Orientation2        currentOrientation          = state.Orientation;
            Orientation2        resultingOrientation        = currentOrientation.RotatedBy(rotatedAmount);
            DynamicOrientation2 resultingDynamicOrientation = new DynamicOrientation2(resultingOrientation, newRotationalVelocity);

            //Use new orientation so that rotating and accelerating rsults in different outputs than just accelerating!
            Vector2 thrustDirection  = resultingDynamicOrientation.Orientation.Facing;
            Vector2 appliedThrust    = data.Acceleration * controls.Axis2 * thrustDirection;
            Vector2 originalVelocity = state.Velocity;
            Vector2 newVelocity      = originalVelocity + deltaTime * appliedThrust;

            float intendedSpeedSq = newVelocity.LengthSquared();

            if (intendedSpeedSq > (data.MaxSpeed * data.MaxSpeed))
            {
                //NOTE: This is not the most accurate approach, but it is somewhat simpler
                newVelocity.Normalize();
                newVelocity   = data.MaxSpeed * newVelocity;
                appliedThrust = (newVelocity - originalVelocity) / deltaTime;
            }

            Vector2          positionDelta            = deltaTime * originalVelocity + 0.5f * (deltaTime * deltaTime) * appliedThrust;
            Vector2          newPosition              = state.Position + positionDelta;
            DynamicPosition2 resultingDynamicPosition = new DynamicPosition2(newPosition, newVelocity);

            return(new DynamicTransform2(resultingDynamicPosition, resultingDynamicOrientation));
        }