GPC_GetButton() public static method

Returns true if the given Button is down.
public static GPC_GetButton ( Button, button ) : bool
button Button,
return bool
コード例 #1
0
    // ShowLevels
    bool ShowLevels()
    {
        if (Scenes.Length == 0)
        {
            ScenesVisible = false;
            return(ScenesVisible);
        }

        bool curStartDown = false;

        if (OVRGamepadController.GPC_GetButton((int)OVRGamepadController.Button.Start) == true)
        {
            curStartDown = true;
        }

        if ((PrevStartDown == false) && (curStartDown == true) ||
            Input.GetKeyDown(KeyCode.RightShift))
        {
            if (ScenesVisible == true)
            {
                ScenesVisible = false;
            }
            else
            {
                ScenesVisible = true;
            }
        }

        PrevStartDown = curStartDown;

        return(ScenesVisible);
    }
コード例 #2
0
    void Update()
    {
        if (fuel < maxFuel)
        {
            fuel = Mathf.Clamp(fuel + Time.deltaTime * fuelReplenishedPerSecond, 0, maxFuel);
        }

        if (flying)
        {
            if ((Input.GetKey(KeyCode.Space) || OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.A)) && fuel > 0)
            {
                fuel -= fuelConsumePerSecond * Time.deltaTime;
                Vector3 moveDir = flightDirection;


                if (playerTransform.position.y < maxHeight)
                {
                    moveDir.y = 1;
                }
                playerTransform.position = playerTransform.position + moveDir * Time.deltaTime * moveSpeed;
            }
            else
            {
                audioSource.Stop();
                flying = false;
            }
        }
        else
        {
            if ((Input.GetKeyDown(KeyCode.Space) || OVRGamepadController.GPC_GetButtonDown(OVRGamepadController.Button.A)) && fuel > 0)
            {
                Audio.PlaySound(jetTakeoff, transform.position);
                audioSource.PlayDelayed(jetTakeoff.length);
                flying            = true;
                flightDirection   = cameraTransform.forward;
                flightDirection.y = 0;
            }
            else
            {
                if (playerTransform.position.y > minHeight)
                {
                    Vector3 moveDir = flightDirection;
                    moveDir.y = -1;

                    playerTransform.position = playerTransform.position + moveDir * Time.deltaTime * moveSpeed;
                    if (playerTransform.position.y <= minHeight)
                    {
                        Audio.PlaySound(jetLand, transform.position);
                    }
                }
            }
        }

        Vector3 finalPos = transform.position;

        finalPos.x = Mathf.Clamp(finalPos.x, -limit.x, limit.x);
        finalPos.z = Mathf.Clamp(finalPos.z, -limit.y, limit.y);

        playerTransform.position = finalPos;
    }
コード例 #3
0
	// GetCurrentLevel
	int GetCurrentLevel()
	{
		bool curHatDown = false;
		if(OVRGamepadController.GPC_GetButton((int)OVRGamepadController.Button.Down) == true)
			curHatDown = true;
		
		bool curHatUp = false;
		if(OVRGamepadController.GPC_GetButton((int)OVRGamepadController.Button.Down) == true)
			curHatUp = true;
		
		if((PrevHatDown == false) && (curHatDown == true) ||
			Input.GetKeyDown(KeyCode.DownArrow))
		{
			CurrentLevel = (CurrentLevel + 1) % SceneNames.Length;	
		}
		else if((PrevHatUp == false) && (curHatUp == true) ||
			Input.GetKeyDown(KeyCode.UpArrow))
		{
			CurrentLevel--;	
			if(CurrentLevel < 0)
				CurrentLevel = SceneNames.Length - 1;
		}
					
		PrevHatDown = curHatDown;
		PrevHatUp = curHatUp;
		
		return CurrentLevel;
	}
コード例 #4
0
    // RIFT RESET ORIENTATION

    // UpdateResetOrientation
    void UpdateResetOrientation()
    {
        if (((ScenesVisible == false) &&
             (OVRGamepadController.GPC_GetButton((int)OVRGamepadController.Button.Down) == true)) ||
            (Input.GetKeyDown(KeyCode.B) == true))
        {
            OVRDevice.ResetOrientation(0);
        }
    }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        bool startPressed = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Start);

        if (startPressed)
        {
            Application.LoadLevel("SeansRoom");
        }
    }
コード例 #6
0
	// UpdateSelectCurrentLevel
	void UpdateSelectCurrentLevel()
	{
		ShowLevels();
				
		if(ScenesVisible == false)
			return;
			
		CurrentLevel = GetCurrentLevel();
		
		if((Scenes.Length != 0) && 
		   ((OVRGamepadController.GPC_GetButton((int)OVRGamepadController.Button.A) == true) ||
			 Input.GetKeyDown(KeyCode.Return)))
		{
			LoadingLevel = true;
			Application.LoadLevelAsync(Scenes[CurrentLevel]);
		}
	}
コード例 #7
0
    // Update is called once per frame
    void Update()
    {
        LineRenderer lineRender;
        RaycastHit   hit;

        bool yPressed = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.Y);

        if (yPressed)
        {
            if (Physics.Raycast(player.transform.position, player.transform.forward, out hit))
            {
                // Draw a line to show the player where they are aiming
                lineRender         = (LineRenderer)line.renderer;
                lineRender.enabled = true;

                lineRender.SetPosition(0, player.transform.position - new Vector3(0.0f, 0.3f, 0.0f));
                lineRender.SetPosition(1, hit.point);
            }
        }
        else if (!yPressed && previousYPressed)
        {
            if (Physics.Raycast(player.transform.position, player.transform.forward, out hit))
            {
                // Create the explosion's particle effect
                Instantiate(explosion, hit.point, Quaternion.identity);

                // Create an explosion around where the player aims
                Collider[] colliders = Physics.OverlapSphere(hit.point, radius);

                foreach (Collider collider in colliders)
                {
                    if (collider.rigidbody == null)
                    {
                        continue;
                    }
                    collider.rigidbody.AddExplosionForce(force, hit.point, radius, 0.0f, ForceMode.Impulse);
                }
            }
            line.renderer.enabled = false;
        }

        previousYPressed = yPressed;
    }
コード例 #8
0
    // Update is called once per frame
    void Update()
    {
        if (OVRGamepadController.GPC_GetButton(0) || Input.GetKey(KeyCode.E))
        {
            RaycastHit hit;
            Ray        rayFired = new Ray(transform.FindChild("OVRCameraController").FindChild("CameraLeft").position +
                                          (transform.FindChild("OVRCameraController").FindChild("CameraLeft").forward *3.0f),
                                          transform.FindChild("OVRCameraController").FindChild("CameraLeft").forward);

            if (Physics.Raycast(rayFired, out hit, pokeDistance))
            {
                if (hit.collider.tag == "user")
                {
                    string id = hit.collider.GetComponentInParent <OVRPlayerController>().GetComponent <PlayerInfo>().id;
                    StartCoroutine(Poker(id));
                }
            }
        }
    }
コード例 #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;
        }

        // 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);
    }
コード例 #10
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();
    }
コード例 #11
0
    // Update is called once per frame
    void Update()
    {
        bool bPressed = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.B);

        if ((game.canFireCircle != null) && (Vector3.Distance(game.canFireCircle.transform.position, transform.position) < game.canFireCircle.transform.localScale.x))
        {
            print("B pressed");
            // Create projectile
            if (bPressed && !previousBDown)
            {
                cubeProjectileObject = (GameObject)Instantiate(cubeProjectile);
            }
            // Animate projectile in front of player
            else if (bPressed)
            {
                print("B being pressed");
                cubeProjectileObject.transform.position = player.transform.position + 2 * player.transform.forward;
                cubeProjectileObject.transform.Rotate(new Vector3(15, 30, 35) * Time.deltaTime);
            }
            // Fire projectile
            else if (!bPressed && previousBDown)
            {
                print("B released");
                cubeProjectileObject.rigidbody.velocity += 8 * player.transform.forward;
                player.audio.Play();
            }

            previousBDown = bPressed;
        }

        //Bomb Projectile
        bool xPressed = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.X);

        // Create projectile
        if (xPressed && !previousXDown)
        {
            if (game.getPushBlocksLeft() > 0)
            {
                game.placePushBlock();
                cubeProjectileObject = (GameObject)Instantiate(cubePush);
            }
            else
            {
                xPressed = false;
            }
        }
        // Animate projectile in front of player
        else if (xPressed)
        {
            print("X being pressed");
            cubeProjectileObject.transform.position = player.transform.position + player.transform.forward;
            cubeProjectileObject.transform.Rotate(new Vector3(15, 30, 35) * Time.deltaTime);
            cubeProjectileObject.rigidbody.constraints = RigidbodyConstraints.FreezePosition;
            cubeProjectileObject.rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
        }
        // Fire projectile
        else if (!xPressed && previousXDown)
        {
            print("X released");
            //cubeProjectileObject.rigidbody.velocity += 8 * player.transform.forward;
            player.audio.Play();
        }

        previousXDown = xPressed;


        // Attaching the Y button to Magnetic Cube
        bool rbPressed = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.RightShoulder);

        // Create projectile
        if (rbPressed && !previousRBDown)
        {
            if (game.getPullBlocksLeft() > 0)
            {
                game.placePullBlock();
//				cubeProjectileObject = (GameObject) Instantiate (cubePush);
                cubeMagnet = (GameObject)Instantiate(cubeMagnet);
            }
            else
            {
                rbPressed = false;
            }
        }
        // Animate projectile in front of player
        else if (rbPressed)
        {
            print("RB being pressed");
            cubeMagnet.transform.position = player.transform.position + player.transform.forward;
            cubeMagnet.transform.Rotate(new Vector3(15, 30, 35) * Time.deltaTime);
            cubeMagnet.rigidbody.constraints = RigidbodyConstraints.FreezePosition;
            cubeMagnet.rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
        }

        // Fire projectile
        else if (!rbPressed && previousRBDown)
        {
            print("RB released");
            //cubeMagnet.rigidbody.velocity += 1 * player.transform.forward;
        }

        previousRBDown = rbPressed;

        // Attaching the Y button to Magnetic Cube
        bool lbPressed = OVRGamepadController.GPC_GetButton(OVRGamepadController.Button.LeftShoulder);

        // Create projectile
        if (lbPressed && !previousLBDown)
        {
            cubeMagnet = (GameObject)Instantiate(cubeBomb);
        }
        // Animate projectile in front of player
        else if (lbPressed)
        {
            print("LB being pressed");
            cubeMagnet.transform.position = player.transform.position + 2 * player.transform.forward;
            cubeMagnet.transform.Rotate(new Vector3(15, 30, 35) * Time.deltaTime);
        }
        // Fire projectile
        else if (!lbPressed && previousLBDown)
        {
            print("LB released");
            cubeMagnet.rigidbody.velocity += 1 * player.transform.forward;
        }

        previousLBDown = lbPressed;
    }
コード例 #12
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);
        }
    }
コード例 #13
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;
        }
    }
コード例 #14
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);
    }
コード例 #15
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);
    }