Ejemplo n.º 1
0
    public static RCC_Inputs GetInputs()
    {
        switch (RCC_Settings.Instance.selectedControllerType)
        {
        case RCC_Settings.ControllerType.Keyboard:

            inputs.throttleInput  = Mathf.Clamp01(Input.GetAxis(RCC_Settings.Instance.verticalInput));
            inputs.brakeInput     = Mathf.Abs(Mathf.Clamp(Input.GetAxis(RCC_Settings.Instance.verticalInput), -1f, 0f));
            inputs.steerInput     = Mathf.Clamp(Input.GetAxis(RCC_Settings.Instance.horizontalInput), -1f, 1f);
            inputs.handbrakeInput = Mathf.Clamp01(Input.GetKey(RCC_Settings.Instance.handbrakeKB) ? 1f : 0f);
            inputs.boostInput     = Mathf.Clamp01(Input.GetKey(RCC_Settings.Instance.boostKB) ? 1f : 0f);

            break;

        case RCC_Settings.ControllerType.XBox360One:

            inputs.throttleInput  = Input.GetAxis(RCC_Settings.Instance.Xbox_triggerRightInput);
            inputs.brakeInput     = Input.GetAxis(RCC_Settings.Instance.Xbox_triggerLeftInput);
            inputs.steerInput     = Input.GetAxis(RCC_Settings.Instance.Xbox_horizontalInput);
            inputs.handbrakeInput = Input.GetButton(RCC_Settings.Instance.Xbox_handbrakeKB) ? 1f : 0f;
            inputs.boostInput     = Input.GetButton(RCC_Settings.Instance.Xbox_boostKB) ? 1f : 0f;

            break;

        case RCC_Settings.ControllerType.Mobile:

            RCC_MobileButtons mobileInput = RCC_MobileButtons.Instance;

            if (mobileInput)
            {
                inputs.throttleInput  = RCC_MobileButtons.Instance.inputs.throttleInput;
                inputs.brakeInput     = RCC_MobileButtons.Instance.inputs.brakeInput;
                inputs.steerInput     = RCC_MobileButtons.Instance.inputs.steerInput;
                inputs.handbrakeInput = RCC_MobileButtons.Instance.inputs.handbrakeInput;
                inputs.boostInput     = RCC_MobileButtons.Instance.inputs.boostInput;
            }

            break;

        case RCC_Settings.ControllerType.LogitechSteeringWheel:

                        #if BCG_LOGITECH
            RCC_LogitechSteeringWheel log = RCC_LogitechSteeringWheel.Instance;

            if (log)
            {
                inputs.throttleInput  = log.inputs.throttleInput;
                inputs.brakeInput     = log.inputs.brakeInput;
                inputs.steerInput     = log.inputs.steerInput;
                inputs.clutchInput    = log.inputs.clutchInput;
                inputs.handbrakeInput = log.inputs.handbrakeInput;
            }
                        #endif

            break;
        }

        return(inputs);
    }
Ejemplo n.º 2
0
    private void Inputs()
    {
        switch (RCCSettings.selectedControllerType)
        {
        case RCC_Settings.ControllerType.Keyboard:

            if (Input.GetKeyDown(RCCSettings.changeCameraKB))
            {
                ChangeCamera();
            }

            orbitX += Input.GetAxis(RCCSettings.mouseXInput) * orbitXSpeed * .02f;
            orbitY -= Input.GetAxis(RCCSettings.mouseYInput) * orbitYSpeed * .02f;

            break;

        case RCC_Settings.ControllerType.XBox360One:

            if (Input.GetButtonDown(RCCSettings.Xbox_changeCameraKB))
            {
                ChangeCamera();
            }

            orbitX += Input.GetAxis(RCCSettings.Xbox_mouseXInput) * orbitXSpeed * .01f;
            orbitY -= Input.GetAxis(RCCSettings.Xbox_mouseYInput) * orbitYSpeed * .01f;

            break;

        case RCC_Settings.ControllerType.LogitechSteeringWheel:

                        #if BCG_LOGITECH
            if (RCC_LogitechSteeringWheel.GetKeyTriggered(0, RCCSettings.LogiSteeringWheel_changeCameraKB))
            {
                ChangeCamera();
            }
                        #endif

            break;
        }
    }
Ejemplo n.º 3
0
    private void TPS()
    {
        if (lastDirection != playerCar.direction)
        {
            direction = playerCar.direction;
            orbitX    = 0f;
            orbitY    = 0f;
        }

        lastDirection = playerCar.direction;

        // Calculate the current rotation angles for TPS mode.
        if (TPSAutoReverse)
        {
            wantedRotation = playerCar.transform.rotation * Quaternion.AngleAxis((direction == 1 ? 0 : 180), Vector3.up);
        }
        else
        {
            wantedRotation = playerCar.transform.rotation;
        }

        switch (RCCSettings.selectedControllerType)
        {
        case RCC_Settings.ControllerType.Keyboard:

            if (Input.GetKey(RCCSettings.lookBackKB))
            {
                wantedRotation = wantedRotation * Quaternion.AngleAxis((180), Vector3.up);
            }

            break;

        case RCC_Settings.ControllerType.XBox360One:

            if (Input.GetButton(RCCSettings.Xbox_lookBackKB))
            {
                wantedRotation = wantedRotation * Quaternion.AngleAxis((180), Vector3.up);
            }

            break;

        case RCC_Settings.ControllerType.LogitechSteeringWheel:

                        #if BCG_LOGITECH
            if (RCC_LogitechSteeringWheel.GetKeyPressed(0, RCCSettings.LogiSteeringWheel_lookBackKB))
            {
                wantedRotation = wantedRotation * Quaternion.AngleAxis((180), Vector3.up);
            }
                        #endif

            break;
        }

        // Wanted height.
        wantedHeight = playerCar.transform.position.y + TPSHeight + TPSOffsetY;

        // Damp the height.
        currentHeight = Mathf.Lerp(currentHeight, wantedHeight, TPSHeightDamping * Time.fixedDeltaTime);

        // Damp the rotation around the y-axis.
        if (Time.time > 1)
        {
            currentRotation = Quaternion.Lerp(currentRotation, wantedRotation, 1f - Mathf.Exp(-TPSRotationDamping * Time.deltaTime));
        }
//			currentRotation = Quaternion.Lerp(currentRotation, wantedRotation, TPSRotationDamping * Time.deltaTime);
        else
        {
            currentRotation = wantedRotation;
        }

        // Rotates camera by Z axis for tilt effect.
        TPSTiltAngle  = Mathf.Lerp(0f, TPSTiltMaximum * Mathf.Clamp(-playerVelocity.x, -1f, 1f), Mathf.Abs(playerVelocity.x) / 50f);
        TPSTiltAngle *= TPSTiltMultiplier;

        // Set the position of the camera on the x-z plane to distance meters behind the target.
        targetPosition  = playerCar.transform.position;
        targetPosition -= (currentRotation * orbitRotation) * Vector3.forward * TPSDistance;
        targetPosition += Vector3.up * (TPSHeight * Mathf.Lerp(1f, .75f, (playerRigid.velocity.magnitude * 3.6f) / 100f));

        transform.position = targetPosition;

//		thisCam.transform.localPosition = Vector3.Lerp(thisCam.transform.localPosition, new Vector3 (TPSTiltAngle / 10f, 0f, 0f), Time.deltaTime * 3f);

        // Always look at the target.
        Vector3 lookAtPosition = playerCar.transform.position;

        if (TPSOffset != Vector3.zero)
        {
            lookAtPosition += playerCar.transform.rotation * TPSOffset;
        }

        transform.LookAt(lookAtPosition);

        transform.position  = transform.position + (transform.right * TPSOffsetX) + (transform.up * TPSOffsetY);
        transform.rotation *= Quaternion.Euler(TPSPitchAngle * Mathf.Lerp(1f, .75f, (playerSpeed) / 100f), 0, Mathf.Clamp(-TPSTiltAngle, -TPSTiltMaximum, TPSTiltMaximum) + TPSYawAngle);

        // Collision positions and rotations that affects pivot of the camera.
        collisionPos = Vector3.Lerp(new Vector3(collisionPos.x, collisionPos.y, collisionPos.z), Vector3.zero, Time.deltaTime * 5f);

        if (Time.deltaTime != 0)
        {
            collisionRot = Quaternion.Lerp(collisionRot, Quaternion.identity, Time.deltaTime * 5f);
        }

        // Lerping position and rotation of the pivot to collision.
        pivot.transform.localPosition = Vector3.Lerp(pivot.transform.localPosition, collisionPos, Time.deltaTime * 10f);
        pivot.transform.localRotation = Quaternion.Lerp(pivot.transform.localRotation, collisionRot, Time.deltaTime * 10f);

        // Lerping targetFieldOfView from TPSMinimumFOV to TPSMaximumFOV related with vehicle speed.
        targetFieldOfView = Mathf.Lerp(TPSMinimumFOV, TPSMaximumFOV, Mathf.Abs(playerSpeed) / 150f);

        if (useOcclusion)
        {
            OccludeRay(playerCar.transform.position);
        }
    }