private void addForceUp() { // xbox control rb.AddForce(Vector3.up * 2 * controllerInput.GetAxisRightTrigger(), ForceMode.Acceleration); // keyboard control if (Input.GetKey(KeyCode.W)) { rb.AddForce(Vector3.up * 2, ForceMode.Acceleration); } if (takeOffStage && (controllerInput.GetAxisRightTrigger() > 0 || Input.GetKey(KeyCode.W))) { takeOffComplete(); } }
/// <summary> /// 获得RT按钮的位移(力度) /// </summary> /// <returns></returns> public float GetAxisRightTrigger() { #if UNITY_METRO && !UNITY_EDITOR return(controllerInput.GetAxisRightTrigger()); #else return(Input.GetAxis("JoystickRT")); #endif }
/* private void translateRotateScale() * { * float moveHorizontal = MoveHorizontalSpeed * controllerInput.GetAxisLeftThumbstickX(); * float moveVertical = MoveVerticalSpeed * controllerInput.GetAxisLeftThumbstickY(); * this.transform.Translate(moveHorizontal, moveVertical, 0.0f); * * float rotateAroundY = RotateAroundYSpeed * controllerInput.GetAxisRightThumbstickX(); * float rotateAroundX = RotateAroundXSpeed * controllerInput.GetAxisRightThumbstickY(); * float rotateAroundZ = RotateAroundZSpeed * (controllerInput.GetAxisRightTrigger() - controllerInput.GetAxisLeftTrigger()); * this.transform.Rotate(rotateAroundX, -rotateAroundY, rotateAroundZ); * * if (controllerInput.GetButton(ControllerButton.DPadUp)) * this.transform.localScale = this.transform.localScale + (this.transform.localScale * ScaleSpeed * Time.deltaTime); * * if (controllerInput.GetButton(ControllerButton.DPadDown)) * this.transform.localScale = this.transform.localScale - (this.transform.localScale * ScaleSpeed * Time.deltaTime); * }*/ private void setAxisInputText() { AxisInputText.text = "LeftThumbstickX: " + controllerInput.GetAxisLeftThumbstickX().ToString() + System.Environment.NewLine + "LeftThumbstickY: " + controllerInput.GetAxisLeftThumbstickY().ToString() + System.Environment.NewLine + "RightThumbstickX: " + controllerInput.GetAxisRightThumbstickX().ToString() + System.Environment.NewLine + "RightThumbstickY: " + controllerInput.GetAxisRightThumbstickY().ToString() + System.Environment.NewLine + "LeftTrigger: " + controllerInput.GetAxisLeftTrigger().ToString() + System.Environment.NewLine + "RightTrigger: " + controllerInput.GetAxisRightTrigger().ToString(); }
private void translateRotateScale() { float moveHorizontal = MoveHorizontalSpeed * controllerInput.GetAxisLeftThumbstickX(); float moveVertical = MoveVerticalSpeed * controllerInput.GetAxisLeftThumbstickY(); this.transform.Translate(moveHorizontal, moveVertical, 0.0f); float rotateAroundY = RotateAroundYSpeed * controllerInput.GetAxisRightThumbstickX(); float rotateAroundX = RotateAroundXSpeed * controllerInput.GetAxisRightThumbstickY(); float rotateAroundZ = RotateAroundZSpeed * (controllerInput.GetAxisRightTrigger() - controllerInput.GetAxisLeftTrigger()); this.transform.Rotate(rotateAroundX, -rotateAroundY, rotateAroundZ); if (controllerInput.GetButton(ControllerButton.DPadUp)) { this.transform.localScale = this.transform.localScale + (this.transform.localScale * ScaleSpeed * Time.deltaTime); } if (controllerInput.GetButton(ControllerButton.DPadDown)) { this.transform.localScale = this.transform.localScale - (this.transform.localScale * ScaleSpeed * Time.deltaTime); } }
// Update is called once per frame void Update() { // Needed ////////////////////////////////////////////////// controllerInput.Update(); /////////////////////////////////////////////////////////// // if RT next, LT previous if (controllerInput.GetAxisRightTrigger() > 0.55) { NextCam(); } if (controllerInput.GetAxisLeftTrigger() > 0.55) { PreviousCam(); } }
void FixedUpdate() { //currentSpeed = capsule.velocity.magnitude; //transform.forward = capsuleCamera.transform.forward; //float h = Input.GetAxis("Mouse Y") * movementSpeed; //for mouse input within unity uncomment these two lines, //float v = Input.GetAxis("Mouse X") * movementSpeed; updateRotation(); if (Input.GetKey("q"))// change the input as the test likes { transform.position += transform.forward * Time.deltaTime * (fowardSpeed + 1); } if (controllerInput.GetAxisRightTrigger() == 1.0f || Input.GetAxis("Right Trigger") == 1.0f)//d-pad { transform.position += transform.forward * Time.deltaTime * (fowardSpeed + 1); } // transform.position = transform.position + Camera.main.transform.forward * distance * Time.deltaTime; }
private void UpdateControls(Vector3 aim) { // Determine angle between user gaze vector and helicopter forward, in xz // plane Vector3 view = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z); Vector3 forward = new Vector3(transform.forward.x, 0, transform.forward.z); float angle = Vector3.Angle(view, forward); // Get current joypad axis values #if UNITY_EDITOR float hor = Input.GetAxis("Horizontal"); float ver = Input.GetAxis("Vertical"); float hor2 = Input.GetAxis("Horizontal2"); float ver2 = -Input.GetAxis("Vertical2"); float lt = Input.GetAxis("Axis9"); float rt = Input.GetAxis("Axis10"); bool buttonA = Input.GetKey(KeyCode.Joystick1Button0); bool buttonB = Input.GetKey(KeyCode.Joystick1Button1); bool fire = rt > 0.5f || buttonA; #else m_xboxController.Update(); float hor = m_xboxController.GetAxisLeftThumbstickX(); float ver = m_xboxController.GetAxisLeftThumbstickY(); float hor2 = m_xboxController.GetAxisRightThumbstickX(); float ver2 = m_xboxController.GetAxisRightThumbstickY(); float lt = m_xboxController.GetAxisLeftTrigger(); float rt = m_xboxController.GetAxisRightTrigger(); bool fire = rt > 0.5f; bool buttonA = m_xboxController.GetButton(ControllerButton.A); bool buttonB = m_xboxController.GetButton(ControllerButton.B); /* * float hor = Input.GetAxis("Horizontal"); * float ver = Input.GetAxis("Vertical"); * float axis3 = Input.GetAxis("Axis3"); * float lt = Mathf.Max(axis3, 0); * float rt = -Mathf.Min(axis3, 0); */ #endif // Any of the main axes (which are relative to orientation) pressed? bool movingThisFrame = (hor != 0) || (ver != 0); if (movingThisFrame && !m_movingLastFrame) { // Joypad was not pressed last frame, reorient based on current view position m_joypadLateralAxis = Vector3.Normalize(Camera.main.transform.right); m_joypadLongitudinalAxis = Vector3.Normalize(Camera.main.transform.forward); } m_movingLastFrame = movingThisFrame; // Apply longitudinal and lateral controls. Compute projection of joypad // lateral/longitudinal axes onto helicopter's. float joypadLongitudinalToHeliLongitudinal = Vector3.Dot(m_joypadLongitudinalAxis, transform.forward); float joypadLongitudinalToHeliLateral = Vector3.Dot(m_joypadLongitudinalAxis, transform.right); float joypadLateralToHeliLongitudinal = Vector3.Dot(m_joypadLateralAxis, transform.forward); float joypadLateralToHeliLateral = Vector3.Dot(m_joypadLateralAxis, transform.right); m_playerControls.longitudinal = joypadLongitudinalToHeliLongitudinal * ver + joypadLateralToHeliLongitudinal * hor; m_playerControls.lateral = joypadLongitudinalToHeliLateral * ver + joypadLateralToHeliLateral * hor; // Helicopter rotation m_playerControls.rotational = hor2; // Altitude control (trigger axes each range from 0 to 1) m_playerControls.altitude = ver2; // Gun if (fire && (Time.time - m_gunLastFired >= GUN_FIRE_PERIOD)) { FireGun(aim); } }