Esempio n. 1
0
        // Do mouse steering
        protected virtual void MouseSteeringUpdate()
        {
            // Get the mouse position in viewport space with 0,0 at the center of the screen
            Vector3 mousePos = new Vector3(Input.mousePosition.x / Screen.width, Input.mousePosition.y / Screen.height, 0) - new Vector3(0.5f, 0.5f, 0f);

            mousePos = mousePos * 2;    // Go from -1 to 1 left to right of screen

            // Adjust the mouse distance taking into account the dead radius
            float mouseDist = Vector3.Magnitude(mousePos);

            mouseDist = Mathf.Max(mouseDist - mouseDeadRadius, 0);
            mousePos  = mousePos.normalized * mouseDist;

            // Update pitch
            rotationInputs.x = Mathf.Clamp((mouseVerticalInverted ? 1 : -1) * mousePos.y * mousePitchSensitivity, -1f, 1f);

            // Linked yaw and roll
            if (linkYawAndRoll)
            {
                rotationInputs.z = Mathf.Clamp(-mousePos.x * mouseRollSensitivity, -1f, 1f);
                rotationInputs.y = Mathf.Clamp(-rotationInputs.z * yawRollRatio, -1f, 1f);
            }
            // Separate axes
            else
            {
                // Roll
                rotationInputs.z = rollAxisInput.FloatValue();

                // Yaw
                rotationInputs.y = Mathf.Clamp(mousePos.x * mouseYawSensitivity, -1f, 1f);
            }
        }
Esempio n. 2
0
        // Do movement
        protected virtual void MovementUpdate()
        {
            // Forward / backward movement
            translationInputs = spaceVehicleEngines.TranslationThrottleValues;
            if (throttleUpInput.Pressed())
            {
                translationInputs.z += throttleSensitivity.z * Time.deltaTime;
            }
            else if (throttleDownInput.Pressed())
            {
                translationInputs.z -= throttleSensitivity.z * Time.deltaTime;
            }

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

            // Up / down movement
            translationInputs.y = strafeVerticalInput.FloatValue();

            // Boost
            if (boostInput.Down())
            {
                boostInputs = new Vector3(0f, 0f, 1f);
            }
            else if (boostInput.Up())
            {
                boostInputs = Vector3.zero;
            }
        }
Esempio n. 3
0
        protected override void InputUpdate()
        {
            base.InputUpdate();

            gimbalController.Rotate(new Vector2(horizontalRotationInputAxis.FloatValue() * gimbalRotationSpeed * Time.deltaTime,
                                                -verticalRotationInputAxis.FloatValue() * gimbalRotationSpeed * Time.deltaTime));
        }
Esempio n. 4
0
        protected void Update()
        {
            if (powerManagementMenuController.MenuActivated)
            {
                // Move power ball horizontally
                powerManagementMenuController.MovePowerBallHorizontally(powerBallMoveHorizontalInput.FloatValue() * powerBallMoveSpeed * Time.unscaledDeltaTime);

                // Move power ball vertically
                powerManagementMenuController.MovePowerBallVertically(powerBallMoveVerticalInput.FloatValue() * powerBallMoveSpeed * Time.unscaledDeltaTime);
            }
        }
Esempio n. 5
0
        // Do keyboard steering
        protected virtual void KeyboardSteeringUpdate()
        {
            // Pitch
            rotationInputs.x = (keyboardVerticalInverted ? -1 : 1) * pitchAxisInput.FloatValue();

            // Linked yaw and roll
            if (linkYawAndRoll)
            {
                rotationInputs.z = -yawAxisInput.FloatValue();
                rotationInputs.y = Mathf.Clamp(-rotationInputs.z * yawRollRatio, -1f, 1f);
            }
            // Separate axes
            else
            {
                // Roll
                rotationInputs.z = rollAxisInput.FloatValue();

                // Yaw
                rotationInputs.y = yawAxisInput.FloatValue();
            }
        }
Esempio n. 6
0
        // Called every frame that this input script is active
        protected override void InputUpdate()
        {
            // Get the next horizontal and vertical inputs for the gimbal
            float horizontalInputValue = Mathf.Lerp(lastHorizontalInputValue, horizontalRotationInput.FloatValue(), 1 / (1 + rotationSmoothing));
            float verticalInputValue   = Mathf.Lerp(lastVerticalInputValue, verticalRotationInput.FloatValue(), 1 / (1 + rotationSmoothing));

            // Rotate the gimbal
            gimballedVehicleController.SetRotationInputs(horizontalInputValue, -verticalInputValue * (invertVerticalInput ? -1 : 1));

            // Update the stored values for the next frame
            lastHorizontalInputValue = horizontalInputValue;
            lastVerticalInputValue   = verticalInputValue;
        }
        // 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));
        }
Esempio n. 8
0
        // Update is called once per frame
        protected override void InputUpdate()
        {
            // Moving
            float horizontal = strafeHorizontalAxisInput.FloatValue();
            float vertical   = walkForwardBackwardAxisInput.FloatValue();

            characterController.SetMovementInputs(horizontal, 0, vertical);

            // Jumping
            if (jumpInput.Down())
            {
                characterController.Jump();
            }

#if !MOBILE_INPUT
            characterController.SetRunning(runInput.Pressed());
#endif
        }
Esempio n. 9
0
        protected override void InputUpdate()
        {
            if (vehicleCamera != null)
            {
                if (cycleViewForwardInput.Down())
                {
                    vehicleCamera.CycleCameraView(true);
                    if (cameraGimbal != null)
                    {
                        cameraGimbal.ResetGimbal();
                    }
                }
                else if (cycleViewBackwardInput.Down())
                {
                    vehicleCamera.CycleCameraView(false);
                    if (cameraGimbal != null)
                    {
                        cameraGimbal.ResetGimbal();
                    }
                }
            }

            if (vehicleCamera.HasCameraViewTarget && vehicleCamera.SelectedCameraViewTarget.CameraView == VehicleCameraView.Interior)
            {
                if (cameraGimbal != null)
                {
                    if (enableLookAroundInput.Pressed())
                    {
                        // Look around
                        cameraGimbal.Rotate(new Vector2(cameraGimbalRotationSpeed * horizontalRotationAxisInput.FloatValue(),
                                                        cameraGimbalRotationSpeed * -verticalRotationAxisInput.FloatValue()));
                    }

                    if (enableLookAroundInput.Up())
                    {
                        cameraGimbal.ResetGimbal();
                    }
                }
            }
        }
Esempio n. 10
0
        protected override void InputUpdate()
        {
            // Cycle camera view
            if (cameraEntity != null)
            {
                if (cycleViewForwardInput.Down())
                {
                    cameraEntity.CycleCameraView(true);
                }
                else if (cycleViewBackwardInput.Down())
                {
                    cameraEntity.CycleCameraView(false);
                }
            }

            // Select camera view
            for (int i = 0; i < cameraViewInputs.Count; ++i)
            {
                if (cameraViewInputs[i].input.Down())
                {
                    cameraEntity.SetView(cameraViewInputs[i].view);
                }
            }

            // Free look mode
            if (cameraGimbalController != null)
            {
                if (freeLookModeInput.Pressed())
                {
                    cameraGimbalController.Rotate(lookHorizontalInput.FloatValue() * freeLookSpeed,
                                                  -lookVerticalInput.FloatValue() * freeLookSpeed);
                }
                else if (freeLookModeInput.Up())
                {
                    cameraGimbalController.ResetGimbal(true);
                }
            }
        }
Esempio n. 11
0
        public virtual void ProcessEvents()
        {
            switch (customInput.inputType)
            {
            case CustomInputType.Axis:

                onInputAxis.Invoke(customInput.FloatValue());

                break;

            default:

                if (customInput.Down())
                {
                    onInputDown.Invoke();
                }
                if (customInput.Up())
                {
                    onInputUp.Invoke();
                }
                break;
            }
        }