/// <summary>
        /// 获得LT按钮的位移(力度)
        /// </summary>
        /// <returns></returns>
        public float GetAxisLeftTrigger()
        {
#if UNITY_METRO && !UNITY_EDITOR
            return(controllerInput.GetAxisLeftTrigger());
#else
            return(Input.GetAxis("JoystickLT"));
#endif
        }
    /* private void translateRotateScale()
     * {
     *   float moveHorizontal = MoveHorizontalSpeed * controllerInput.GetAxisLeftThumbstickX();
     *   float moveVertical = MoveVerticalSpeed * controllerInput.GetAxisLeftThumbstickY();
     *   this.transform.Translate(moveHorizontal, moveVertical, 0.0f);
     *
     *   float rotateAroundY = RotateAroundYSpeed * controllerInput.GetAxisRightThumbstickX();
     *   float rotateAroundX = RotateAroundXSpeed * controllerInput.GetAxisRightThumbstickY();
     *   float rotateAroundZ = RotateAroundZSpeed * (controllerInput.GetAxisRightTrigger() - controllerInput.GetAxisLeftTrigger());
     *   this.transform.Rotate(rotateAroundX, -rotateAroundY, rotateAroundZ);
     *
     *   if (controllerInput.GetButton(ControllerButton.DPadUp))
     *       this.transform.localScale = this.transform.localScale + (this.transform.localScale * ScaleSpeed * Time.deltaTime);
     *
     *   if (controllerInput.GetButton(ControllerButton.DPadDown))
     *       this.transform.localScale = this.transform.localScale - (this.transform.localScale * ScaleSpeed * Time.deltaTime);
     * }*/

    private void setAxisInputText()
    {
        AxisInputText.text =
            "LeftThumbstickX: " + controllerInput.GetAxisLeftThumbstickX().ToString() + System.Environment.NewLine +
            "LeftThumbstickY: " + controllerInput.GetAxisLeftThumbstickY().ToString() + System.Environment.NewLine +
            "RightThumbstickX: " + controllerInput.GetAxisRightThumbstickX().ToString() + System.Environment.NewLine +
            "RightThumbstickY: " + controllerInput.GetAxisRightThumbstickY().ToString() + System.Environment.NewLine +
            "LeftTrigger: " + controllerInput.GetAxisLeftTrigger().ToString() + System.Environment.NewLine +
            "RightTrigger: " + controllerInput.GetAxisRightTrigger().ToString();
    }
    private void addForceDown()
    {
        // xbox control
        rb.AddForce(Vector3.down * 2 * controllerInput.GetAxisLeftTrigger(), ForceMode.Acceleration);

        // keyboard control
        if (Input.GetKey(KeyCode.S))
        {
            rb.AddForce(Vector3.down * 2, ForceMode.Acceleration);
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (transform.hasChanged)
     {
     }
     if (controllerInput.GetAxisLeftTrigger() == 1.0f)
     {
         emissionPoint = createEmissionPoint();
         createRing();
         drawRing();
     }
 }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        // Needed //////////////////////////////////////////////////
        controllerInput.Update();
        ///////////////////////////////////////////////////////////

        // if RT next, LT previous
        if (controllerInput.GetAxisRightTrigger() > 0.55)
        {
            NextCam();
        }
        if (controllerInput.GetAxisLeftTrigger() > 0.55)
        {
            PreviousCam();
        }
    }
예제 #6
0
    private void translateRotateScale()
    {
        float moveHorizontal = MoveHorizontalSpeed * controllerInput.GetAxisLeftThumbstickX();
        float moveVertical   = MoveVerticalSpeed * controllerInput.GetAxisLeftThumbstickY();

        this.transform.Translate(moveHorizontal, moveVertical, 0.0f);

        float rotateAroundY = RotateAroundYSpeed * controllerInput.GetAxisRightThumbstickX();
        float rotateAroundX = RotateAroundXSpeed * controllerInput.GetAxisRightThumbstickY();
        float rotateAroundZ = RotateAroundZSpeed * (controllerInput.GetAxisRightTrigger() - controllerInput.GetAxisLeftTrigger());

        this.transform.Rotate(rotateAroundX, -rotateAroundY, rotateAroundZ);

        if (controllerInput.GetButton(ControllerButton.DPadUp))
        {
            this.transform.localScale = this.transform.localScale + (this.transform.localScale * ScaleSpeed * Time.deltaTime);
        }

        if (controllerInput.GetButton(ControllerButton.DPadDown))
        {
            this.transform.localScale = this.transform.localScale - (this.transform.localScale * ScaleSpeed * Time.deltaTime);
        }
    }
예제 #7
0
    private void UpdateControls(Vector3 aim)
    {
        // Determine angle between user gaze vector and helicopter forward, in xz
        // plane
        Vector3 view    = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z);
        Vector3 forward = new Vector3(transform.forward.x, 0, transform.forward.z);
        float   angle   = Vector3.Angle(view, forward);

        // Get current joypad axis values
#if UNITY_EDITOR
        float hor     = Input.GetAxis("Horizontal");
        float ver     = Input.GetAxis("Vertical");
        float hor2    = Input.GetAxis("Horizontal2");
        float ver2    = -Input.GetAxis("Vertical2");
        float lt      = Input.GetAxis("Axis9");
        float rt      = Input.GetAxis("Axis10");
        bool  buttonA = Input.GetKey(KeyCode.Joystick1Button0);
        bool  buttonB = Input.GetKey(KeyCode.Joystick1Button1);
        bool  fire    = rt > 0.5f || buttonA;
#else
        m_xboxController.Update();
        float hor     = m_xboxController.GetAxisLeftThumbstickX();
        float ver     = m_xboxController.GetAxisLeftThumbstickY();
        float hor2    = m_xboxController.GetAxisRightThumbstickX();
        float ver2    = m_xboxController.GetAxisRightThumbstickY();
        float lt      = m_xboxController.GetAxisLeftTrigger();
        float rt      = m_xboxController.GetAxisRightTrigger();
        bool  fire    = rt > 0.5f;
        bool  buttonA = m_xboxController.GetButton(ControllerButton.A);
        bool  buttonB = m_xboxController.GetButton(ControllerButton.B);

        /*
         * float hor = Input.GetAxis("Horizontal");
         * float ver = Input.GetAxis("Vertical");
         * float axis3 = Input.GetAxis("Axis3");
         * float lt = Mathf.Max(axis3, 0);
         * float rt = -Mathf.Min(axis3, 0);
         */
#endif

        // Any of the main axes (which are relative to orientation) pressed?
        bool movingThisFrame = (hor != 0) || (ver != 0);
        if (movingThisFrame && !m_movingLastFrame)
        {
            // Joypad was not pressed last frame, reorient based on current view position
            m_joypadLateralAxis      = Vector3.Normalize(Camera.main.transform.right);
            m_joypadLongitudinalAxis = Vector3.Normalize(Camera.main.transform.forward);
        }
        m_movingLastFrame = movingThisFrame;

        // Apply longitudinal and lateral controls. Compute projection of joypad
        // lateral/longitudinal axes onto helicopter's.
        float joypadLongitudinalToHeliLongitudinal = Vector3.Dot(m_joypadLongitudinalAxis, transform.forward);
        float joypadLongitudinalToHeliLateral      = Vector3.Dot(m_joypadLongitudinalAxis, transform.right);
        float joypadLateralToHeliLongitudinal      = Vector3.Dot(m_joypadLateralAxis, transform.forward);
        float joypadLateralToHeliLateral           = Vector3.Dot(m_joypadLateralAxis, transform.right);
        m_playerControls.longitudinal = joypadLongitudinalToHeliLongitudinal * ver + joypadLateralToHeliLongitudinal * hor;
        m_playerControls.lateral      = joypadLongitudinalToHeliLateral * ver + joypadLateralToHeliLateral * hor;

        // Helicopter rotation
        m_playerControls.rotational = hor2;

        // Altitude control (trigger axes each range from 0 to 1)
        m_playerControls.altitude = ver2;

        // Gun
        if (fire && (Time.time - m_gunLastFired >= GUN_FIRE_PERIOD))
        {
            FireGun(aim);
        }
    }