Example #1
0
    void OnEventAxisControlShip(CUserInput.EAxis _eAxis, ulong _ulPlayerId, float _fValue)
    {
        if (_ulPlayerId != 0 &&
            _ulPlayerId == m_cCockpitBehaviour.MountedPlayerId)
        {
            CGalaxyShipMotor cGalaxyShipMotor = CGameShips.GalaxyShip.GetComponent <CGalaxyShipMotor>();

            switch (_eAxis)
            {
            case CUserInput.EAxis.MouseX:
                if (_fValue == 0.0f)
                {
                    cGalaxyShipMotor.SetThrusterEnabled(CGalaxyShipMotor.EThrusters.RollLeft, 0.0f);
                    cGalaxyShipMotor.SetThrusterEnabled(CGalaxyShipMotor.EThrusters.RollRight, 0.0f);
                }
                else
                {
                    if (_fValue > 0.0f)
                    {
                        // / Screen.width
                        cGalaxyShipMotor.SetThrusterEnabled(CGalaxyShipMotor.EThrusters.RollLeft, Mathf.Clamp(_fValue / 15, 0.0f, 1.0f));
                        cGalaxyShipMotor.SetThrusterEnabled(CGalaxyShipMotor.EThrusters.RollRight, 0.0f);
                    }
                    else
                    {
                        cGalaxyShipMotor.SetThrusterEnabled(CGalaxyShipMotor.EThrusters.RollLeft, 0.0f);
                        cGalaxyShipMotor.SetThrusterEnabled(CGalaxyShipMotor.EThrusters.RollRight, Mathf.Clamp(_fValue / 15 * -1.0f, 0.0f, 1.0f));
                    }
                }
                break;

            case CUserInput.EAxis.MouseY:
                if (_fValue == 0.0f)
                {
                    cGalaxyShipMotor.SetThrusterEnabled(CGalaxyShipMotor.EThrusters.PitchUp, 0.0f);
                    cGalaxyShipMotor.SetThrusterEnabled(CGalaxyShipMotor.EThrusters.PitchDown, 0.0f);
                }
                else
                {
                    if (_fValue > 0.0f)
                    {
                        // / Screen.width
                        cGalaxyShipMotor.SetThrusterEnabled(CGalaxyShipMotor.EThrusters.PitchUp, Mathf.Clamp(_fValue / 20, 0.0f, 1.0f));
                        cGalaxyShipMotor.SetThrusterEnabled(CGalaxyShipMotor.EThrusters.PitchDown, 0.0f);
                    }
                    else
                    {
                        cGalaxyShipMotor.SetThrusterEnabled(CGalaxyShipMotor.EThrusters.PitchUp, 0.0f);
                        cGalaxyShipMotor.SetThrusterEnabled(CGalaxyShipMotor.EThrusters.PitchDown, Mathf.Clamp(_fValue / 20 * -1.0f, 0.0f, 1.0f));
                    }
                }
                break;

            default:
                Debug.LogError("Unknown input");
                break;
            }
        }
    }
Example #2
0
    private void OnMouseMoveY(CUserInput.EAxis _eAxis, float _fAmount)
    {
        if (!InputDisabled)
        {
            // Retrieve new rotations
            m_LocalXRotation += _fAmount;

            // Clamp rotation
            m_LocalXRotation = Mathf.Clamp(m_LocalXRotation, m_vCameraMinRotation.x, m_vCameraMaxRotation.x);

            // Apply the pitch to the camera
            SetHeadRotations(m_LocalXRotation);
        }
    }
Example #3
0
    private void OnEventClientAxisControlTurret(CUserInput.EAxis _eAxis, ulong _ulPlayerId, float _fValue)
    {
        if (_ulPlayerId == m_ulControllerPlayerId.Get())
        {
            if (transform.FindChild("MechanicalComponent").GetComponent <CActorHealth>().health > 0)
            {
                switch (_eAxis)
                {
                case CUserInput.EAxis.MouseX:
                {
                    Vector2 vRotation = new Vector2(m_cBarrel.transform.eulerAngles.x, transform.rotation.eulerAngles.y);

                    // Update rotation
                    vRotation.y += _fValue;

                    // Apply rotations to turret
                    transform.localEulerAngles           = new Vector3(0.0f, vRotation.y, 0.0f);
                    m_cBarrel.transform.localEulerAngles = new Vector3(vRotation.x, 0.0f, 0.0f);

                    // Server updates the rotation for other clients
                    m_tRotation.Set(new Vector2(vRotation.x, vRotation.y));
                    break;
                }

                case CUserInput.EAxis.MouseY:
                {
                    Vector2 vRotation = new Vector2(m_cBarrel.transform.eulerAngles.x, transform.rotation.eulerAngles.y);

                    // Update rotation
                    vRotation.x += _fValue;
                    vRotation.x  = Mathf.Clamp(vRotation.x, m_fMinRotationX, m_fMaxRotationX);

                    // Apply rotations to turret
                    transform.localEulerAngles           = new Vector3(0.0f, vRotation.y, 0.0f);
                    m_cBarrel.transform.localEulerAngles = new Vector3(vRotation.x, 0.0f, 0.0f);

                    // Server updates the rotation for other clients
                    m_tRotation.Set(new Vector2(vRotation.x, vRotation.y));
                    break;
                }

                default:
                    Debug.LogError("Unknown input");
                    break;
                }
            }
        }
    }