GPC_GetAxis() public static method

Returns the current value of the given Axis.
public static GPC_GetAxis ( Axis, axis ) : float
axis Axis,
return float
コード例 #1
0
        /// <summary>
        /// Get extra scroll delta from gamepad
        /// </summary>
        protected Vector2 GetExtraScrollDelta()
        {
            Vector2 scrollDelta = new Vector2();

            if (useLeftStickScroll)
            {
                float x = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftXAxis);
                float y = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftYAxis);
                if (Mathf.Abs(x) < leftStickDeadZone)
                {
                    x = 0;
                }
                if (Mathf.Abs(y) < leftStickDeadZone)
                {
                    y = 0;
                }
                scrollDelta = new Vector2(x, y);
            }
            return(scrollDelta);
        }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (AllowMovement)
        {
            float gamePad_FwdAxis    = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftYAxis);
            float gamePad_StrafeAxis = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftXAxis);

            Vector3 fwdMove    = (CameraRig.centerEyeAnchor.rotation * Vector3.forward) * gamePad_FwdAxis * Time.deltaTime * ForwardSpeed;
            Vector3 strafeMove = (CameraRig.centerEyeAnchor.rotation * Vector3.right) * gamePad_StrafeAxis * Time.deltaTime * StrafeSpeed;
            transform.position += fwdMove + strafeMove;
        }

        if (!UnityEngine.XR.XRDevice.isPresent && (AllowYawLook || AllowPitchLook))
        {
            Quaternion r = transform.rotation;
            if (AllowYawLook)
            {
                float      gamePadYaw = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.RightXAxis);
                float      yawAmount  = gamePadYaw * Time.deltaTime * GamePad_YawDegreesPerSec;
                Quaternion yawRot     = Quaternion.AngleAxis(yawAmount, Vector3.up);
                r = yawRot * r;
            }
            if (AllowPitchLook)
            {
                float gamePadPitch = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.RightYAxis);
                if (Mathf.Abs(gamePadPitch) > 0.0001f)
                {
                    if (InvertPitch)
                    {
                        gamePadPitch *= -1.0f;
                    }
                    float      pitchAmount = gamePadPitch * Time.deltaTime * GamePad_PitchDegreesPerSec;
                    Quaternion pitchRot    = Quaternion.AngleAxis(pitchAmount, Vector3.left);
                    r = r * pitchRot;
                }
            }

            transform.rotation = r;
        }
    }
コード例 #3
0
    void Update()
    {
        shotLimit = WeaponMgr.ACTIVE_WEAPON.FireRate;

        if (!m_oculusConnected)
        {
            SetupMouseLookat();
        }

        // skip tutorial, restart etc.
        ListenForMenuButtons();
        // previous, next weapon
        ListenToWeaponCycle();

        CycleWeapons();

        // TODO: also check if 0, then reset timer
        if (Input.GetMouseButtonDown(0) || Mathf.Abs(OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.RightTrigger)) > 0 || Input.GetMouseButton(0))
        {
            // shoot and other stuff
            if (m_timeSinceShot <= shotLimit)
            {
                m_timeSinceShot += Time.deltaTime * 1000.0f; // add time in ms
                return;
            }
            else
            {
                m_timeSinceShot = 0;
                Shoot();
            }
        }

        if (Input.GetKeyDown(KeyCode.R) || OVRGamepadController.GPC_GetButtonDown(OVRGamepadController.Button.B))
        {
            Application.LoadLevel(Application.loadedLevelName);
        }
    }
コード例 #4
0
    public virtual void UpdateMovement()
    {
        if (HaltUpdateMovement)
        {
            return;
        }

        bool moveForward = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow);
        bool moveLeft    = Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
        bool moveRight   = Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
        bool moveBack    = Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow);

        bool dpad_move = false;

        if (OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Up))
        {
            moveForward = true;
            dpad_move   = true;
        }
        if (OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Down))
        {
            moveBack  = true;
            dpad_move = true;
        }

        MoveScale = 1.0f;

        if ((moveForward && moveLeft) || (moveForward && moveRight) ||
            (moveBack && moveLeft) || (moveBack && moveRight))
        {
            MoveScale = 0.70710678f;
        }

        // No positional movement if we are in the air
        if (!Controller.isGrounded)
        {
            MoveScale = 0.0f;
        }

        MoveScale *= SimulationRate * Time.deltaTime;

        // Compute this for key movement
        float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        if (dpad_move || Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            moveInfluence *= 2.0f;
        }

        Quaternion ort      = (HmdRotatesY) ? CameraController.centerEyeAnchor.rotation : transform.rotation;
        Vector3    ortEuler = ort.eulerAngles;

        ortEuler.z = ortEuler.x = 0f;
        ort        = Quaternion.Euler(ortEuler);

        if (moveForward)
        {
            MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * Vector3.forward);
        }
        if (moveBack)
        {
            MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * BackAndSideDampen * Vector3.back);
        }
        if (moveLeft)
        {
            MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.left);
        }
        if (moveRight)
        {
            MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.right);
        }

        bool curHatLeft = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.LeftShoulder);

        Vector3 euler = transform.rotation.eulerAngles;

        if (curHatLeft && !prevHatLeft)
        {
            euler.y -= RotationRatchet;
        }

        prevHatLeft = curHatLeft;

        bool curHatRight = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.RightShoulder);

        if (curHatRight && !prevHatRight)
        {
            euler.y += RotationRatchet;
        }

        prevHatRight = curHatRight;

        //Use keys to ratchet rotation
        if (Input.GetKeyDown(KeyCode.Q))
        {
            euler.y -= RotationRatchet;
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            euler.y += RotationRatchet;
        }

        float rotateInfluence = SimulationRate * Time.deltaTime * RotationAmount * RotationScaleMultiplier;

        if (!SkipMouseRotation)
        {
            euler.y += Input.GetAxis("Mouse X") * rotateInfluence * 3.25f;
        }

        moveInfluence = SimulationRate * Time.deltaTime * Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

#if !UNITY_ANDROID // LeftTrigger not avail on Android game pad
        moveInfluence *= 1.0f + OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftTrigger);
#endif

        float leftAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftXAxis);
        float leftAxisY = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftYAxis);

        if (leftAxisY > 0.0f)
        {
            MoveThrottle += ort * (leftAxisY * moveInfluence * Vector3.forward);
        }

        if (leftAxisY < 0.0f)
        {
            MoveThrottle += ort * (Mathf.Abs(leftAxisY) * moveInfluence * BackAndSideDampen * Vector3.back);
        }

        if (leftAxisX < 0.0f)
        {
            MoveThrottle += ort * (Mathf.Abs(leftAxisX) * moveInfluence * BackAndSideDampen * Vector3.left);
        }

        if (leftAxisX > 0.0f)
        {
            MoveThrottle += ort * (leftAxisX * moveInfluence * BackAndSideDampen * Vector3.right);
        }

        float rightAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.RightXAxis);

        euler.y += rightAxisX * rotateInfluence;

        transform.rotation = Quaternion.Euler(euler);
    }
コード例 #5
0
    /// <summary>
    /// Updates the player's movement.
    /// </summary>
    public virtual void UpdateMovement()
    {
        // Do not apply input if we are showing a level selection display
        if (HaltUpdateMovement == true)
        {
            return;
        }
        if (Application.loadedLevel != 0)
        {
            moveForward = false;
        }
        bool moveLeft  = false;
        bool moveRight = false;
        bool moveBack  = false;

        MoveScale = 2.0f;

        // * * * * * * * * * * *
        // Keyboard input

        // Move

        // WASD
        if (Input.GetKey(KeyCode.W))
        {
            moveForward = true;
        }
        if (Input.GetKey(KeyCode.A))
        {
            moveLeft = true;
        }
        if (Input.GetKey(KeyCode.S))
        {
            moveBack = true;
        }
        if (Input.GetKey(KeyCode.D))
        {
            moveRight = true;
        }
        // Arrow keys
        if (Input.GetKey(KeyCode.UpArrow))
        {
            if (moveForward)
            {
                moveForward = false;
            }
            else
            {
                moveForward = true;
            }
        }
        //if (Input.GetKey(KeyCode.LeftArrow))  moveLeft      = true;
        if (Input.GetKey(KeyCode.DownArrow))
        {
            moveBack = true;
        }
        //if (Input.GetKey(KeyCode.RightArrow)) moveRight   = true;
        //Jump
        float x = 0;
        float y = 0;
        float z = 0;

        if (Application.loadedLevel == 0)
        {
            if (Input.GetKey(KeyCode.J))
            {
                Jump();
            }
            if (OVRDevice.GetAcceleration(ref x, ref y, ref z))
            {
                if (y > 1.5 && x < 0.3 && z < 0.3)
                {
                    Jump();
                }
            }
        }

        //Restart
        if (Input.GetKey(KeyCode.Return))
        {
            myTimer = 300.0f;
            Application.LoadLevel("Scaled");
        }



        // D-Pad
        bool dpad_move = false;

        if (OVRGamepadController.GPC_GetButton((int)OVRGamepadController.Button.Up) == true)
        {
            moveForward = true;
            dpad_move   = true;
        }
        if (OVRGamepadController.GPC_GetButton((int)OVRGamepadController.Button.Down) == true)
        {
            moveBack  = true;
            dpad_move = true;
        }

        if ((moveForward && moveLeft) || (moveForward && moveRight) ||
            (moveBack && moveLeft) || (moveBack && moveRight))
        {
            MoveScale = 0.70710678f;
        }

        // No positional movement if we are in the air
        //if (!Controller.isGrounded)
        //MoveScale = 0.0f;

        MoveScale *= OVRDevice.SimulationRate * Time.deltaTime;

        // Compute this for key movement
        float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            moveInfluence *= 2.0f;
        }
        else if (dpad_move)
        {
            moveInfluence *= 3.0f;
        }

        if (DirXform != null)
        {
            if (moveForward)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.forward * moveInfluence * transform.lossyScale.z);
            }
            if (moveBack)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.back * moveInfluence * transform.lossyScale.z) * BackAndSideDampen;
            }
            if (moveLeft)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.left * moveInfluence * transform.lossyScale.x) * BackAndSideDampen;
            }
            if (moveRight)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.right * moveInfluence * transform.lossyScale.x) * BackAndSideDampen;
            }
        }

        // Rotate

        // D-Pad rachet

        bool curHatLeft = false;

        if (OVRGamepadController.GPC_GetButton((int)OVRGamepadController.Button.Left) == true)
        {
            curHatLeft = true;
        }

        if (curHatLeft && !prevHatLeft)
        {
            YRotation -= RotationRatchet;
        }

        prevHatLeft = curHatLeft;

        bool curHatRight = false;

        if (OVRGamepadController.GPC_GetButton((int)OVRGamepadController.Button.Right) == true)
        {
            curHatRight = true;
        }

        if (curHatRight && !prevHatRight)
        {
            YRotation += RotationRatchet;
        }

        prevHatRight = curHatRight;

        //Use keys to ratchet rotation
        if (Input.GetKeyDown(KeyCode.Q))
        {
            YRotation -= RotationRatchet;
        }
        if (Input.GetKeyDown(KeyCode.E))
        {
            YRotation += RotationRatchet;
        }

        // * * * * * * * * * * *
        // Mouse input

        // Move

        // Rotate

        // compute for key rotation
        float rotateInfluence = OVRDevice.SimulationRate * Time.deltaTime * RotationAmount * RotationScaleMultiplier;

        float deltaRotation = 0.0f;

        if (SkipMouseRotation == false)
        {
            deltaRotation = Input.GetAxis("Mouse X") * rotateInfluence * 3.25f;
        }

        float filteredDeltaRotation = (sDeltaRotationOld * 0.0f) + (deltaRotation * 1.0f);

        YRotation        += filteredDeltaRotation;
        sDeltaRotationOld = filteredDeltaRotation;

        // * * * * * * * * * * *
        // XBox controller input

        // Compute this for xinput movement
        moveInfluence = OVRDevice.SimulationRate * Time.deltaTime * Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        moveInfluence *= 1.0f +
                         OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.LeftTrigger);

        // Move
        if (DirXform != null)
        {
            float leftAxisY =
                OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.LeftYAxis);

            float leftAxisX =
                OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.LeftXAxis);

            if (leftAxisY > 0.0f)
            {
                MoveThrottle += leftAxisY *
                                DirXform.TransformDirection(Vector3.forward * moveInfluence);
            }

            if (leftAxisY < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisY) *
                                DirXform.TransformDirection(Vector3.back * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisX) *
                                DirXform.TransformDirection(Vector3.left * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX > 0.0f)
            {
                MoveThrottle += leftAxisX *
                                DirXform.TransformDirection(Vector3.right * moveInfluence) * BackAndSideDampen;
            }
        }

        float rightAxisX =
            OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.RightXAxis);

        // Rotate
        YRotation += rightAxisX * rotateInfluence;

        // Update cameras direction and rotation
        SetCameras();
    }
コード例 #6
0
    public virtual void UpdateMovement()
    {
        if (HaltUpdateMovement)
        {
            return;
        }

        bool moveForward = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow);
        bool moveLeft    = Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
        bool moveRight   = Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
        bool moveBack    = Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow);

        bool dpad_move = false;

        if (OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Up))
        {
            moveForward = true;
            dpad_move   = true;
        }
        if (OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Down))
        {
            moveBack  = true;
            dpad_move = true;
        }

        MoveScale = 1.0f;

        if ((moveForward && moveLeft) || (moveForward && moveRight) ||
            (moveBack && moveLeft) || (moveBack && moveRight))
        {
            MoveScale = 0.70710678f;
        }

        // No positional movement if we are in the air
        if (!Controller.isGrounded)
        {
            MoveScale = 0.0f;
        }

        MoveScale *= SimulationRate * Time.deltaTime;

        // Compute this for key movement
        float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        if (dpad_move || Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            moveInfluence *= 2.0f;
        }

        if (DirXform != null)
        {
            if (moveForward)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.forward * moveInfluence * transform.lossyScale.z);
            }
            if (moveBack)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.back * moveInfluence * transform.lossyScale.z) * BackAndSideDampen;
            }
            if (moveLeft)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.left * moveInfluence * transform.lossyScale.x) * BackAndSideDampen;
            }
            if (moveRight)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.right * moveInfluence * transform.lossyScale.x) * BackAndSideDampen;
            }
        }

        bool curHatLeft = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.LeftShoulder);

        if (curHatLeft && !prevHatLeft)
        {
            YRotation -= RotationRatchet;
        }

        prevHatLeft = curHatLeft;

        bool curHatRight = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.RightShoulder);

        if (curHatRight && !prevHatRight)
        {
            YRotation += RotationRatchet;
        }

        prevHatRight = curHatRight;



        //Use keys to ratchet rotation xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        if (Input.GetKeyDown(KeyCode.Q))
        {
            StartCoroutine(WaitAndTurnL());
        }


        if (Input.GetKeyDown(KeyCode.E))
        {
            StartCoroutine(WaitAndTurnR());
        }

        float rotateInfluence = SimulationRate * Time.deltaTime * RotationAmount * RotationScaleMultiplier;

        if (!SkipMouseRotation)
        {
            YRotation += Input.GetAxis("Mouse X") * rotateInfluence * 3.25f;
        }

        moveInfluence = SimulationRate * Time.deltaTime * Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

#if !UNITY_ANDROID // LeftTrigger not avail on Android game pad
        moveInfluence *= 1.0f + OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftTrigger);
#endif

        if (DirXform != null)
        {
            float leftAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftXAxis);
            float leftAxisY = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftYAxis);

            if (leftAxisY > 0.0f)
            {
                MoveThrottle += leftAxisY
                                * DirXform.TransformDirection(Vector3.forward * moveInfluence);
            }

            if (leftAxisY < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisY)
                                * DirXform.TransformDirection(Vector3.back * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisX)
                                * DirXform.TransformDirection(Vector3.left * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX > 0.0f)
            {
                MoveThrottle += leftAxisX
                                * DirXform.TransformDirection(Vector3.right * moveInfluence) * BackAndSideDampen;
            }
        }

        float rightAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.RightXAxis);

        YRotation += rightAxisX * rotateInfluence;

        DirXform.rotation  = Quaternion.Euler(0.0f, YRotation, 0.0f);
        transform.rotation = DirXform.rotation;

        if (HmdRotatesY)
        {
            float hmdY = CameraController.centerEyeAnchor.localRotation.eulerAngles.y;
            DirXform.rotation *= Quaternion.Euler(0.0f, hmdY, 0.0f);
        }
    }
コード例 #7
0
    /// <summary>
    /// Updates the movement.
    /// </summary>
    public virtual void UpdateMovement()
    {
        // Do not apply input if we are showing a level selection display
        if (HaltUpdateMovement == true)
        {
            return;
        }

        bool moveForward = false;
        bool moveLeft    = false;
        bool moveRight   = false;
        bool moveBack    = false;

        MoveScale = 1.0f;

        // * * * * * * * * * * *
        // Keyboard input

        // Move

        // WASD
        if (Input.GetKey(KeyCode.W))
        {
            moveForward = true;
        }
        if (Input.GetKey(KeyCode.A))
        {
            moveLeft = true;
        }
        if (Input.GetKey(KeyCode.S))
        {
            moveBack = true;
        }
        if (Input.GetKey(KeyCode.D))
        {
            moveRight = true;
        }
        // Arrow keys
        if (Input.GetKey(KeyCode.UpArrow))
        {
            moveForward = true;
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            moveLeft = true;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            moveBack = true;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            moveRight = true;
        }

        if ((moveForward && moveLeft) || (moveForward && moveRight) ||
            (moveBack && moveLeft) || (moveBack && moveRight))
        {
            MoveScale = 0.70710678f;
        }

        // No positional movement if we are in the air
        if (!Controller.isGrounded)
        {
            MoveScale = 0.0f;
        }

        MoveScale *= DeltaTime;

        // Compute this for key movement
        float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            moveInfluence *= 2.0f;
        }

        if (DirXform != null)
        {
            if (moveForward)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.forward * moveInfluence * transform.lossyScale.z);
            }
            if (moveBack)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.back * moveInfluence * transform.lossyScale.z) * BackAndSideDampen;
            }
            if (moveLeft)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.left * moveInfluence * transform.lossyScale.x) * BackAndSideDampen;
            }
            if (moveRight)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.right * moveInfluence * transform.lossyScale.x) * BackAndSideDampen;
            }
        }

        // Rotate

        // compute for key rotation
        float rotateInfluence = DeltaTime * RotationAmount * RotationScaleMultiplier;

        //reduce by half to avoid getting ill
        if (Input.GetKey(KeyCode.Q))
        {
            YRotation -= rotateInfluence * 0.5f;
        }
        if (Input.GetKey(KeyCode.E))
        {
            YRotation += rotateInfluence * 0.5f;
        }

        // * * * * * * * * * * *
        // Mouse input

        // Move

        // Rotate
        float deltaRotation = 0.0f;

        if (AllowMouseRotation == false)
        {
            deltaRotation = Input.GetAxis("Mouse X") * rotateInfluence * 3.25f;
        }

        float filteredDeltaRotation = (sDeltaRotationOld * 0.0f) + (deltaRotation * 1.0f);

        YRotation        += filteredDeltaRotation;
        sDeltaRotationOld = filteredDeltaRotation;

        // * * * * * * * * * * *
        // XBox controller input

        // Compute this for xinput movement
        moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        moveInfluence *= 1.0f +
                         OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.LeftTrigger);

        // Move
        if (DirXform != null)
        {
            float leftAxisY =
                OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.LeftYAxis);

            float leftAxisX =
                OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.LeftXAxis);

            if (leftAxisY > 0.0f)
            {
                MoveThrottle += leftAxisY *
                                DirXform.TransformDirection(Vector3.forward * moveInfluence);
            }

            if (leftAxisY < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisY) *
                                DirXform.TransformDirection(Vector3.back * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisX) *
                                DirXform.TransformDirection(Vector3.left * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX > 0.0f)
            {
                MoveThrottle += leftAxisX *
                                DirXform.TransformDirection(Vector3.right * moveInfluence) * BackAndSideDampen;
            }
        }

        float rightAxisX =
            OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.RightXAxis);

        // Rotate
        YRotation += rightAxisX * rotateInfluence;

        // Update cameras direction and rotation
        SetCameras();
    }
コード例 #8
0
    public virtual void UpdateMovement()
    {
        if (HaltUpdateMovement)
        {
            return;
        }


        bool moveLeft  = Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
        bool moveRight = Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
        bool moveBack  = Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow);

        bool dpad_move = false;

        if (OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Left))
        {
            moveForward = false;
        }

        if (OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Right))
        {
            moveForward = false;
        }


        if (moveForward)
        {
            MoveScale = 2;
        }

        if (boosting)
        {
            if (boostStartTime + boostTime > Time.time)
            {
                MoveScale *= boostMultiplier;
            }
            else
            {
                boosting = false;
            }
        }

        if (stopped)
        {
            MoveScale = 0;
        }

        MoveScale *= SimulationRate * Time.deltaTime;

        // Compute this for key movement
        float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        if (dpad_move || Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            moveInfluence *= 2.0f;
        }

        Quaternion ort      = transform.rotation;
        Vector3    ortEuler = ort.eulerAngles;

        ortEuler.z = ortEuler.x = 0f;
        ort        = Quaternion.Euler(ortEuler);

        if (moveForward)
        {
            MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * Vector3.forward);
        }
        if (moveBack)
        {
            MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * BackAndSideDampen * Vector3.back);
        }
        if (moveLeft)
        {
            MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.left);
        }
        if (moveRight)
        {
            MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.right);
        }

        Vector3 euler = transform.rotation.eulerAngles;

        bool curHatLeft = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.LeftShoulder);

        if (curHatLeft && !prevHatLeft)
        {
            euler.y -= RotationRatchet;
        }

        prevHatLeft = curHatLeft;

        bool curHatRight = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.RightShoulder);

        if (curHatRight && !prevHatRight)
        {
            euler.y += RotationRatchet;
        }

        prevHatRight = curHatRight;

        //Use keys to ratchet rotation
        if (Input.GetKeyDown(KeyCode.Q))
        {
            euler.y -= RotationRatchet;
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            euler.y += RotationRatchet;
        }

        float rotateInfluence = SimulationRate * Time.deltaTime * RotationAmount * RotationScaleMultiplier;

#if !UNITY_ANDROID || UNITY_EDITOR
        if (!SkipMouseRotation)
        {
            euler.y += Input.GetAxis("Mouse X") * rotateInfluence * 3.25f;
        }
#endif

        moveInfluence = SimulationRate * Time.deltaTime * Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

#if !UNITY_ANDROID // LeftTrigger not avail on Android game pad
        moveInfluence *= 1.0f + OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftTrigger);
#endif

        float leftAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftXAxis);
        float leftAxisY = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftYAxis);

        if (leftAxisY > 0.0f)
        {
            MoveThrottle += ort * (leftAxisY * moveInfluence * Vector3.forward);
        }

        if (leftAxisY < 0.0f)
        {
            MoveThrottle += ort * (Mathf.Abs(leftAxisY) * moveInfluence * BackAndSideDampen * Vector3.back);
        }

        if (leftAxisX < 0.0f)
        {
            MoveThrottle += ort * (Mathf.Abs(leftAxisX) * moveInfluence * BackAndSideDampen * Vector3.left);
        }

        if (leftAxisX > 0.0f)
        {
            MoveThrottle += ort * (leftAxisX * moveInfluence * BackAndSideDampen * Vector3.right);
        }

        float rightAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.RightXAxis);

        euler.y += rightAxisX * rotateInfluence;

        transform.rotation = Quaternion.Euler(euler);

        if (Controller.isGrounded && MoveThrottle.y < 0)
        {
            MoveThrottle.y = 0;
        }
    }
コード例 #9
0
    public virtual void UpdateMovement()
    {
        if (HaltUpdateMovement)
        {
            return;
        }

        bool moveForward = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow);
        bool moveLeft    = Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
        bool moveRight   = Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
        bool moveBack    = Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow);

        bool dpad_move = false;

        if (OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Up))
        {
            moveForward = true;
            dpad_move   = true;
        }
        if (OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Down))
        {
            moveBack  = true;
            dpad_move = true;
        }

        MoveScale = 1.0f;

        if ((moveForward && moveLeft) || (moveForward && moveRight) ||
            (moveBack && moveLeft) || (moveBack && moveRight))
        {
            MoveScale = 0.70710678f;
        }



        if (!Controller.isGrounded)
        {
            MoveScale = 0;
        }


        //ZZ: button press for testing
        if (Input.GetKeyDown(KeyCode.W))
        {
            if (isWalkAround == true)
            {
                isWalkAround = false;
            }
            else
            {
                isWalkAround = true;
            }
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            if (isBreathAcceleration == true)
            {
                isBreathAcceleration = false;
            }
            else
            {
                isBreathAcceleration = true;
            }
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            if (isBreathDeceleration == true)
            {
                isBreathDeceleration = false;
            }
            else
            {
                isBreathDeceleration = true;
            }
        }



        //ZZ: use Look Camera object to manipulate navigation when in air or walking around.
        if (isWalkAround)
        {
            Vector3 forwardDir    = lookCamera.transform.forward;
            Vector3 forwardScaler = new Vector3(1, 0, 1) * moveForwardScale;
            Vector3 forwardFinal  = Vector3.Scale(forwardDir, forwardScaler);
            Controller.Move(forwardFinal);
        }

        if (isFinal)
        {
            Vector3 forwardDir    = lookCamera.transform.forward;
            Vector3 forwardScaler = new Vector3(1, 1, 1) * moveForwardScale;
            Vector3 forwardFinal  = Vector3.Scale(forwardDir, forwardScaler);
            Controller.Move(forwardFinal);
        }

        //ZZ: use breath to manipulate falling speed when in air and breath accelerating.
        if (!Controller.isGrounded && isBreathAcceleration)
        {
            tempPos   = this.transform.position;
            tempAcel += new Vector3(0, acelScale, 0);
            tempVel  += tempAcel;
            Debug.Log("tempVel.y :" + tempVel.y + "acc");
            tempPos += tempVel;
            this.transform.position = tempPos;
        }
        if (!Controller.isGrounded && isBreathDeceleration)
        {
            if (tempVel.y < -1 * moveDownScale)
            {
                isBreathAcceleration = false;
                tempPos    = this.transform.position;
                tempVel.y += recoverScale;
                Debug.Log("tempVel.y :" + tempVel.y + "dec");
                tempPos += tempVel;
                this.transform.position = tempPos;
            }
            else
            {
                isBreathDeceleration = false;
            }
        }


        MoveScale *= SimulationRate * Time.deltaTime;

        // Compute this for key movement
        float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        if (dpad_move || Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            moveInfluence *= 2.0f;
        }

        Quaternion ort      = transform.rotation;
        Vector3    ortEuler = ort.eulerAngles;

        ortEuler.z = ortEuler.x = 0f;
        ort        = Quaternion.Euler(ortEuler);

        if (moveForward)
        {
            MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * Vector3.forward);
        }
        if (moveBack)
        {
            MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * BackAndSideDampen * Vector3.back);
        }
        if (moveLeft)
        {
            MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.left);
        }
        if (moveRight)
        {
            MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.right);
        }

        bool curHatLeft = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.LeftShoulder);

        Vector3 euler = transform.rotation.eulerAngles;

        if (curHatLeft && !prevHatLeft)
        {
            euler.y -= RotationRatchet;
        }

        prevHatLeft = curHatLeft;

        bool curHatRight = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.RightShoulder);

        if (curHatRight && !prevHatRight)
        {
            euler.y += RotationRatchet;
        }

        prevHatRight = curHatRight;

        //Use keys to ratchet rotation
        if (Input.GetKeyDown(KeyCode.Q))
        {
            euler.y -= RotationRatchet;
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            euler.y += RotationRatchet;
        }

        float rotateInfluence = SimulationRate * Time.deltaTime * RotationAmount * RotationScaleMultiplier;

        if (!SkipMouseRotation)
        {
            euler.y += Input.GetAxis("Mouse X") * rotateInfluence * 3.25f;
        }

        moveInfluence = SimulationRate * Time.deltaTime * Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

#if !UNITY_ANDROID // LeftTrigger not avail on Android game pad
        moveInfluence *= 1.0f + OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftTrigger);
#endif

        float leftAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftXAxis);
        float leftAxisY = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftYAxis);

        if (leftAxisY > 0.0f)
        {
            MoveThrottle += ort * (leftAxisY * moveInfluence * Vector3.forward);
        }

        if (leftAxisY < 0.0f)
        {
            MoveThrottle += ort * (Mathf.Abs(leftAxisY) * moveInfluence * BackAndSideDampen * Vector3.back);
        }

        if (leftAxisX < 0.0f)
        {
            MoveThrottle += ort * (Mathf.Abs(leftAxisX) * moveInfluence * BackAndSideDampen * Vector3.left);
        }

        if (leftAxisX > 0.0f)
        {
            MoveThrottle += ort * (leftAxisX * moveInfluence * BackAndSideDampen * Vector3.right);
        }

        float rightAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.RightXAxis);

        euler.y += rightAxisX * rotateInfluence;

        transform.rotation = Quaternion.Euler(euler);
    }
コード例 #10
0
    public virtual void UpdateMovement()
    {
        if (HaltUpdateMovement)
        {
            return;
        }

        bool moveForward = hotkey.moveForward;
        bool moveLeft    = hotkey.moveLeft;
        bool moveRight   = hotkey.moveRight;
        bool moveBack    = hotkey.moveBack;

        //adding moveing up and moving down functions
        bool moveUpDown = hotkey.moveY;
        bool dpad_move  = false;

        if (OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Up))
        {
            moveForward = true;
            dpad_move   = true;
        }
        if (OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Down))
        {
            moveBack  = true;
            dpad_move = true;
        }

        MoveScale = 1.0f;

        if ((moveForward && moveLeft) || (moveForward && moveRight) ||
            (moveBack && moveLeft) || (moveBack && moveRight))
        {
            MoveScale = 0.70710678f;
        }

        // No positional movement if we are in the air
        // That is what you think
        if (!Controller.isGrounded)
        {
            MoveScale = NoGravityMovement;
        }

        MoveScale *= SimulationRate * Time.deltaTime;

        // Compute this for key movement
        float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        if (dpad_move || hotkey.run)
        {
            moveInfluence *= 2.0f;
        }

        Quaternion ort      = (HmdRotatesY) ? CameraController.centerEyeAnchor.rotation : transform.rotation;
        Vector3    ortEuler = ort.eulerAngles;

        ortEuler.z = ortEuler.x = 0f;
        ort        = Quaternion.Euler(ortEuler);

        if (moveForward)
        {
            if (moveUpDown)
            {
                MoveThrottle += ort * (transform.lossyScale.y * moveInfluence * Vector3.up);
            }
            else
            {
                MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * Vector3.forward);
            }
        }
        if (moveBack)
        {
            if (moveUpDown)
            {
                MoveThrottle += ort * (transform.lossyScale.y * moveInfluence * Vector3.down);
            }
            else
            {
                MoveThrottle += ort * (transform.lossyScale.z * moveInfluence * BackAndSideDampen * Vector3.back);
            }
        }
        if (moveLeft)
        {
            MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.left);
        }

        if (moveRight)
        {
            MoveThrottle += ort * (transform.lossyScale.x * moveInfluence * BackAndSideDampen * Vector3.right);
        }

        bool curHatLeft = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.LeftShoulder);

        Vector3 euler = transform.rotation.eulerAngles;

        if (curHatLeft && !prevHatLeft)
        {
            euler.y -= RotationRatchet;
        }

        prevHatLeft = curHatLeft;

        bool curHatRight = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.RightShoulder);

        if (curHatRight && !prevHatRight)
        {
            euler.y += RotationRatchet;
        }

        prevHatRight = curHatRight;

        //Use keys to ratchet rotation
        if (hotkey.ratchetLeft)
        {
            euler.y -= RotationRatchet;
        }

        if (hotkey.ratchetRight)
        {
            euler.y += RotationRatchet;
        }

        float rotateInfluence = SimulationRate * Time.deltaTime * RotationAmount * RotationScaleMultiplier;


        moveInfluence = SimulationRate * Time.deltaTime * Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

#if !UNITY_ANDROID // LeftTrigger not avail on Android game pad
        moveInfluence *= 1.0f + OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftTrigger);
#endif

        float leftAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftXAxis);
        float leftAxisY = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftYAxis);

        if (leftAxisY > 0.0f)
        {
            MoveThrottle += ort * (leftAxisY * moveInfluence * Vector3.forward);
        }

        if (leftAxisY < 0.0f)
        {
            MoveThrottle += ort * (Mathf.Abs(leftAxisY) * moveInfluence * BackAndSideDampen * Vector3.back);
        }

        if (leftAxisX < 0.0f)
        {
            MoveThrottle += ort * (Mathf.Abs(leftAxisX) * moveInfluence * BackAndSideDampen * Vector3.left);
        }

        if (leftAxisX > 0.0f)
        {
            MoveThrottle += ort * (leftAxisX * moveInfluence * BackAndSideDampen * Vector3.right);
        }

        float rightAxisX = OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.RightXAxis);

        euler.y += rightAxisX * rotateInfluence;

        transform.rotation = Quaternion.Euler(euler);
    }
コード例 #11
0
    public virtual void UpdateMovement()
    {
        // Do not apply input if we are showing a level selection display
        if (HaltUpdateMovement == true)
        {
            return;
        }

        bool moveForward = false;
        bool moveLeft    = false;
        bool moveRight   = false;
        bool moveBack    = false;

        MoveScale = 1.0f;

        // * * * * * * * * * * *
        // Keyboard input

        // Move

        // WASD
        if (Input.GetKey(KeyCode.W))
        {
            moveForward = true;
        }
        if (Input.GetKey(KeyCode.A))
        {
            moveLeft = true;
        }
        if (Input.GetKey(KeyCode.S))
        {
            moveBack = true;
        }
        if (Input.GetKey(KeyCode.D))
        {
            moveRight = true;
        }
        // Arrow keys
        if (Input.GetKey(KeyCode.UpArrow))
        {
            moveForward = true;
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            moveLeft = true;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            moveBack = true;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            moveRight = true;
        }
        if (Input.GetKeyDown(KeyCode.R) || Input.GetButtonDown("ButtonStart"))
        {
            Reset();
        }
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            SwitchItem();
        }


        float lt = Input.GetAxis("TriggersL_1");
        float rt = Input.GetAxis("TriggersR_1");


        if (!LeftTriggerDown && lt == 1)
        {
            SwitchItem(true);
            LeftTriggerDown = true;
        }
        else if (LeftTriggerDown && lt == -1)
        {
            LeftTriggerDown = false;
        }

        if (!RightTriggerDown && rt == 1)
        {
            SwitchItem(false);
            RightTriggerDown = true;
        }
        else if (RightTriggerDown && rt == -1)
        {
            RightTriggerDown = false;
        }

        if ((moveForward && moveLeft) || (moveForward && moveRight) ||
            (moveBack && moveLeft) || (moveBack && moveRight))
        {
            MoveScale = 0.70710678f;
        }

        // No positional movement if we are in the air
        //if (!Controller.isGrounded)
        //MoveScale = 0.0f;

        if (Input.GetButtonDown("ButtonA") || Input.GetKeyDown(KeyCode.Space))
        {
            Jump();
        }


        //if(JumpItem != null) {
        if ((Input.GetKeyDown(KeyCode.F) || Input.GetButtonDown("ButtonB")) && JumpItem.isUsable)
        {
            JumpItem.Activate();
        }
        JumpItem.Update();
        //}

        MoveScale *= DeltaTime;

        // Compute this for key movement
        float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            moveInfluence *= 2.0f;
        }

        if (DirXform != null)
        {
            if (moveForward)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.forward * moveInfluence);
            }
            if (moveBack)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.back * moveInfluence) * BackAndSideDampen;
            }
            if (moveLeft)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.left * moveInfluence) * BackAndSideDampen;
            }
            if (moveRight)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.right * moveInfluence) * BackAndSideDampen;
            }
        }

        // Rotate

        // compute for key rotation
        float rotateInfluence = DeltaTime * RotationAmount * RotationScaleMultiplier;

        //reduce by half to avoid getting ill
        if (Input.GetKey(KeyCode.Q))
        {
            YRotation -= rotateInfluence * 0.5f;
        }
        if (Input.GetKey(KeyCode.E))
        {
            YRotation += rotateInfluence * 0.5f;
        }

        // * * * * * * * * * * *
        // Mouse input

        // Move

        // Rotate
        float deltaRotation = 0.0f;

        if (AllowMouseRotation == false)
        {
            deltaRotation = Input.GetAxis("R_XAxis_0") * rotateInfluence * 3.25f;
        }

        float filteredDeltaRotation = (sDeltaRotationOld * 0.0f) + (deltaRotation * 1.0f);

        YRotation        += filteredDeltaRotation;
        sDeltaRotationOld = filteredDeltaRotation;

        // * * * * * * * * * * *
        // XBox controller input

        // Compute this for xinput movement
        moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        float leftAxisY = Input.GetAxis("L_YAxis_1");

        float leftAxisX = Input.GetAxis("L_XAxis_1");

        float axisStrength = Mathf.Abs(leftAxisY) > Mathf.Abs(leftAxisX) ? Mathf.Abs(leftAxisY) : Mathf.Abs(leftAxisX);

        // Run!
        moveInfluence *= 1.0f + axisStrength;

        // Move
        if (DirXform != null)
        {
            if (leftAxisY > 0.0f)
            {
                MoveThrottle += leftAxisY *
                                DirXform.TransformDirection(Vector3.forward * moveInfluence);
            }

            if (leftAxisY < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisY) *
                                DirXform.TransformDirection(Vector3.back * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisX) *
                                DirXform.TransformDirection(Vector3.left * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX > 0.0f)
            {
                MoveThrottle += leftAxisX *
                                DirXform.TransformDirection(Vector3.right * moveInfluence) * BackAndSideDampen;
            }
        }

        float rightAxisX =
            OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.RightXAxis);

        // Rotate
        YRotation += rightAxisX * rotateInfluence;

        if (transform.position.y < 0)
        {
            Stop();
            Die();
        }


        // Update cameras direction and rotation
        SetCameras();
    }
コード例 #12
0
    /// <summary>
    /// Updates the player's movement.
    /// </summary>
    public virtual void UpdateMovement()
    {
        // Do not apply input if we are showing a level selection display
        if (HaltUpdateMovement == true)
        {
            return;
        }

        bool moveForward = false;
        bool moveLeft    = false;
        bool moveRight   = false;
        bool moveBack    = false;

        MoveScale = 1.0f;

        // * * * * * * * * * * *
        // Keyboard input

        // Move

        // WASD
        if (Input.GetKey(KeyCode.W))
        {
            moveForward = true;
        }
        if (Input.GetKey(KeyCode.A))
        {
            moveLeft = true;
        }
        if (Input.GetKey(KeyCode.S))
        {
            moveBack = true;
        }
        if (Input.GetKey(KeyCode.D))
        {
            moveRight = true;
        }
        // Arrow keys
        if (Input.GetKey(KeyCode.UpArrow))
        {
            moveForward = true;
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            moveLeft = true;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            moveBack = true;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            moveRight = true;
        }

        if ((moveForward && moveLeft) || (moveForward && moveRight) ||
            (moveBack && moveLeft) || (moveBack && moveRight))
        {
            MoveScale = 0.70710678f;
        }

        // No positional movement if we are in the air
        if (!Controller.isGrounded)
        {
            MoveScale = 0.0f;
        }

        MoveScale *= OVRDevice.FrameRate * Time.deltaTime;

        // Compute this for key movement
        float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            moveInfluence *= 2.0f;
        }

        if (DirXform != null)
        {
            if (moveForward)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.forward * moveInfluence * transform.lossyScale.z);
            }
            if (moveBack)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.back * moveInfluence * transform.lossyScale.z) * BackAndSideDampen;
            }
            if (moveLeft)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.left * moveInfluence * transform.lossyScale.x) * BackAndSideDampen;
            }
            if (moveRight)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.right * moveInfluence * transform.lossyScale.x) * BackAndSideDampen;
            }
        }

        // Rotate

        // IMPORTANT ANDROID NOTE:
        // As of Unity 4.4b2, the right thumbstick on the Samsung gamepad is not identified
        // automatically.  You must go to edit->project_settings->input and set
        // Right_X_Axis Axis to "14th axis (Joysticks)"
        // Right_Y_Axis Axis to "15th axis (Joysticks)"

        // compute for key rotation
        float rotateInfluence = OVRDevice.FrameRate * Time.deltaTime * RotationAmount * RotationScaleMultiplier;

        //reduce by half to avoid getting ill
        if (Input.GetKey(KeyCode.Q))
        {
            YRotation -= rotateInfluence * 0.5f;
        }
        if (Input.GetKey(KeyCode.E))
        {
            YRotation += rotateInfluence * 0.5f;
        }

        // * * * * * * * * * * *
        // Mouse input

        // Move

        // Rotate
        float deltaRotation = 0.0f;

        if (SkipMouseRotation == false)
        {
            deltaRotation = Input.GetAxis("Mouse X") * rotateInfluence * 3.25f;
        }

        float filteredDeltaRotation = (sDeltaRotationOld * 0.0f) + (deltaRotation * 1.0f);

        YRotation        += filteredDeltaRotation;
        sDeltaRotationOld = filteredDeltaRotation;

        // * * * * * * * * * * *
        // XBox controller input

        // Compute this for xinput movement
        moveInfluence = OVRDevice.FrameRate * Time.deltaTime * Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

#if (!UNITY_ANDROID)    // LeftTrigger not avail on Android game pad
        // Run!
        moveInfluence *= 1.0f +
                         OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftTrigger);
#endif

        // Move
        if (DirXform != null)
        {
            float leftAxisY =
                OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftYAxis);

            float leftAxisX =
                OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.LeftXAxis);

            if (leftAxisY > 0.0f)
            {
                MoveThrottle += leftAxisY *
                                DirXform.TransformDirection(Vector3.forward * moveInfluence);
            }

            if (leftAxisY < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisY) *
                                DirXform.TransformDirection(Vector3.back * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisX) *
                                DirXform.TransformDirection(Vector3.left * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX > 0.0f)
            {
                MoveThrottle += leftAxisX *
                                DirXform.TransformDirection(Vector3.right * moveInfluence) * BackAndSideDampen;
            }
        }

        float rightAxisX =
            OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.RightXAxis);

#if (UNITY_ANDROID && !UNITY_EDITOR) // TODO: Only enable when sensor not active
        float rightAxisY = 0.0f;
#else
        float rightAxisY =
            OVRGamepadController.GPC_GetAxis(OVRGamepadController.Axis.RightYAxis);
#endif

        // Rotate
        YRotation += rightAxisX * rotateInfluence;
        XRotation += rightAxisY * rotateInfluence;              // no idea why YRotation uses X axis and vice versa

        // Update cameras direction and rotation
        SetCameras();
    }
コード例 #13
0
    public virtual void UpdateMovement()
    {
        // Do not apply input if we are showing a level selection display
        if (HaltUpdateMovement == true)
        {
            return;
        }

        bool moveForward = false;
        bool moveLeft    = false;
        bool moveRight   = false;
        bool moveBack    = false;
        bool moveUp      = false;
        bool moveDown    = false;

        MoveScale = 1.0f;
        //Debug.Log("in drop is" + inDrop);
        if (nav_obj.remainingDistance >= 3.0f && inDrop == false)         //
        {
            nav_obj.speed = 7.0f;
        }

        // * * * * * * * * * * *
        // Keyboard input

        // Move

        // WASD
        if (Input.GetKey(KeyCode.W))
        {
            moveUp = true;
        }
        if (Input.GetKey(KeyCode.A))
        {
            moveLeft = true;
        }
        if (Input.GetKey(KeyCode.S))
        {
            moveDown = true;
        }
        if (Input.GetKey(KeyCode.D))
        {
            moveRight = true;
        }

        if ((Input.GetKey(KeyCode.T) || uniWii.buttonAPressed) && globalObj.currentStamina > 0)
        {
            moveForward = true;
        }

        if (Input.GetKey(KeyCode.R))
        {
            moveBack = true;                                      //|| uniWii.YAccel > 135.0f
        }
        int c = uniWii.wiiCount;

        if (c > 0)
        {
//			if(uniWii.YAccel < 120.0f || uniWii.YAccel > 140.0f)
//			{
//
//				gameObject.rigidbody.AddForce(0,0,-500);
//			}


            if ((uniWii.YAccel > 160.0f) &&
                (uniWii.pitch > 45.0f && uniWii.pitch < 150.0f) //&&
                //((uniWii.roll < -120 &&  uniWii.roll > -180) || (uniWii.roll > 120 &&  uniWii.roll < 180))
                )                                               //uniWii.YAccel < 120.0f ||
            {
                //nav_obj.speed += 4.0f;
                moveForward = true;
                //gameObject.rigidbody.velocity +=
                // Forward thrust control for Wii
                //nav_obj.speed += 1;
            }
            else if ((uniWii.ZAccel < 95.0f || uniWii.ZAccel > 180.0f) &&
                     (uniWii.pitch < -125.0f && uniWii.pitch > -180.0f) || (uniWii.pitch > 155.0f && uniWii.pitch < 180.0f))
            {
                moveBack = true;
                //gameObject.rigidbody.AddForce(0,0,500);
            }
            else if (uniWii.roll < -45 && uniWii.roll > -145)
            {
                moveLeft = true;
            }
            else if (uniWii.roll > 45 && uniWii.roll < 145)
            {
                moveRight = true;
            }
//				{
//
//					gameObject.rigidbody.velocity.Set(0,0,-10000);
//				}
        }

        // Arrow keys
        if (Input.GetKey(KeyCode.UpArrow) || uniWii.buttonUpPressed)
        {
            moveUp = true;
        }
        if (Input.GetKey(KeyCode.LeftArrow) || uniWii.buttonLeftPressed)
        {
            moveLeft = true;
        }
        if (Input.GetKey(KeyCode.DownArrow) || uniWii.buttonDownPressed)
        {
            moveDown = true;
        }
        if (Input.GetKey(KeyCode.RightArrow) || uniWii.buttonRightPressed)
        {
            moveRight = true;
        }

        if ((moveForward && moveLeft) || (moveForward && moveRight) ||
            (moveBack && moveLeft) || (moveBack && moveRight))
        {
            MoveScale = 0.70710678f;
        }

        // No positional movement if we are in the air
        //if (!Controller.isGrounded)
        //MoveScale = 0.0f;

        MoveScale *= DeltaTime;

        // Compute this for key movement
        float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            moveInfluence *= 2.0f;
        }

        if (DirXform != null)
        {
            if (moveForward)
            {
                if (nav_obj.remainingDistance >= 15.0f)               //&& (nav_obj.remainingDistance != float.NegativeInfinity && nav_obj.remainingDistance != float.PositiveInfinity))
                {
                    nav_obj.speed     = 20.0f;
                    obs_nav_obj.speed = 20.0f;

                    // Decrease stamina
                    globalObj.currentStamina -= Constants.STAMINA_DEC_RATE;
                }
                else
                {
                    MoveThrottle += DirXform.TransformDirection(Vector3.forward * moveInfluence);
                    //nav_obj.speed = nav_obj.remainingDistance;
                }
            }
            if (moveBack)
            {
                if (nav_obj.remainingDistance >= float.Epsilon)               //&& (nav_obj.remainingDistance != float.NegativeInfinity && nav_obj.remainingDistance != float.PositiveInfinity))
                {
                    nav_obj.speed     = 2.0f;
                    obs_nav_obj.speed = 1.0f;

                    // Decrease stamina
                    globalObj.currentStamina -= Constants.STAMINA_DEC_RATE;
                }
                else
                {
                    MoveThrottle += DirXform.TransformDirection(Vector3.back * moveInfluence) * BackAndSideDampen;
                }
            }
            if (moveLeft)
            {
                if (nav_obj.remainingDistance >= 15.0f)               //&& (nav_obj.remainingDistance != float.NegativeInfinity && nav_obj.remainingDistance != float.PositiveInfinity))
                {
                    nav_obj.transform.position += DirXform.TransformDirection(Vector3.left * moveInfluence) * BackAndSideDampen * 10.0f;
                }
                else
                {
                    MoveThrottle += DirXform.TransformDirection(Vector3.left * moveInfluence) * BackAndSideDampen;
                }
            }
            if (moveRight)
            {
                if (nav_obj.remainingDistance >= 15.0f)               //&& (nav_obj.remainingDistance != float.NegativeInfinity && nav_obj.remainingDistance != float.PositiveInfinity))
                {
                    nav_obj.transform.position += DirXform.TransformDirection(Vector3.right * moveInfluence) * BackAndSideDampen * 10.0f;
                }
                else
                {
                    MoveThrottle += DirXform.TransformDirection(Vector3.right * moveInfluence) * BackAndSideDampen;
                }
            }
            if (moveUp)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.up * moveInfluence);
            }
            if (moveDown)
            {
                MoveThrottle += DirXform.TransformDirection(Vector3.down * moveInfluence) * BackAndSideDampen;
            }
        }

        // Rotate

        // compute for key rotation
        float rotateInfluence = DeltaTime * RotationAmount * RotationScaleMultiplier;

        //reduce by half to avoid getting ill
        if (Input.GetKey(KeyCode.Q))
        {
            YRotation -= rotateInfluence * 0.5f;
        }
        if (Input.GetKey(KeyCode.E))
        {
            YRotation += rotateInfluence * 0.5f;
        }

        // * * * * * * * * * * *
        // Mouse input

        // Move

        // Rotate
        float deltaRotation = 0.0f;

        if (AllowMouseRotation == false)
        {
            deltaRotation = Input.GetAxis("Mouse X") * rotateInfluence * 3.25f;
        }

        float filteredDeltaRotation = (sDeltaRotationOld * 0.0f) + (deltaRotation * 1.0f);

        YRotation        += filteredDeltaRotation;
        sDeltaRotationOld = filteredDeltaRotation;

        // * * * * * * * * * * *
        // XBox controller input

        // Compute this for xinput movement
        moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

        // Run!
        moveInfluence *= 1.0f +
                         OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.LeftTrigger);

        // Move
        if (DirXform != null)
        {
            float leftAxisY =
                OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.LeftYAxis);

            float leftAxisX =
                OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.LeftXAxis);

            if (leftAxisY > 0.0f)
            {
                MoveThrottle += leftAxisY *
                                DirXform.TransformDirection(Vector3.forward * moveInfluence);
            }

            if (leftAxisY < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisY) *
                                DirXform.TransformDirection(Vector3.back * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX < 0.0f)
            {
                MoveThrottle += Mathf.Abs(leftAxisX) *
                                DirXform.TransformDirection(Vector3.left * moveInfluence) * BackAndSideDampen;
            }

            if (leftAxisX > 0.0f)
            {
                MoveThrottle += leftAxisX *
                                DirXform.TransformDirection(Vector3.right * moveInfluence) * BackAndSideDampen;
            }
        }

        float rightAxisX =
            OVRGamepadController.GPC_GetAxis((int)OVRGamepadController.Axis.RightXAxis);

        // Rotate
        YRotation += rightAxisX * rotateInfluence;

        // Auto orientation
        if (nav_obj.remainingDistance >= 15.0f)       //&& (nav_obj.remainingDistance != float.NegativeInfinity && nav_obj.remainingDistance != float.PositiveInfinity))
        {
            YRotation = nav_obj.transform.rotation.eulerAngles.y;
        }

        // Update cameras direction and rotation
        SetCameras();
    }