// Set the control values for the vehicle
        void SetControlValues()
        {
            // Values to be passed to the ship
            float pitch = 0;
            float yaw   = 0;
            float roll  = 0;

            Vector3 flattenedForward = new Vector3(engines.transform.forward.x, 0f, engines.transform.forward.z).normalized;

            Maneuvring.TurnToward(engines.transform, engines.transform.position + flattenedForward, new Vector3(0f, 360f, 0f), shipPIDController.steeringPIDController);

            pitch = shipPIDController.steeringPIDController.GetControlValue(PIDController3D.Axis.X);
            roll  = shipPIDController.steeringPIDController.GetControlValue(PIDController3D.Axis.Z);

            yaw = -yawInput.FloatValue();


            // ************************** Throttle ******************************

            Vector3 nextTranslationInputs = engines.TranslationThrottleValues;

            if (throttleUpInput.Pressed())
            {
                nextTranslationInputs.z += throttleSensitivity.z * Time.deltaTime;
            }
            else if (throttleDownInput.Pressed())
            {
                nextTranslationInputs.z -= throttleSensitivity.z * Time.deltaTime;
            }

            // Left / right movement
            nextTranslationInputs.x = strafeHorizontalInput.FloatValue();

            // Up / down movement
            nextTranslationInputs.y = strafeVerticalInput.FloatValue();
            engines.SetTranslationThrottleValues(nextTranslationInputs);


            if (boostInput.Down())
            {
                engines.SetBoostThrottleValues(new Vector3(0f, 0f, 1f));
            }
            else if (boostInput.Up())
            {
                engines.SetBoostThrottleValues(Vector3.zero);
            }

            engines.SetRotationThrottleValues(new Vector3(pitch, yaw, roll));
        }
Beispiel #2
0
        /// <summary>
        /// Stop the input.
        /// </summary>
        public override void StopInput()
        {
            base.StopInput();

            // Reset the space vehicle engines to idle
            if (spaceVehicleEngines != null)
            {
                // Set steering to zero
                rotationInputs = Vector3.zero;
                spaceVehicleEngines.SetRotationThrottleValues(rotationInputs);

                // Set movement to zero
                translationInputs = Vector3.zero;
                spaceVehicleEngines.SetTranslationThrottleValues(translationInputs);

                // Set boost to zero
                boostInputs = Vector3.zero;
                spaceVehicleEngines.SetBoostThrottleValues(boostInputs);
            }
        }