// Update is called once per frame void Update() { controllerInput.Update(); float rotation_z = this.transform.localEulerAngles.z; float rotation_y = this.transform.localEulerAngles.y; float rotation_x = this.transform.localEulerAngles.x; // Debug.Log(rotation_y); if (Input.GetAxis("rotate_h") < 0 || controllerInput.GetAxisRightThumbstickX() < 0) { rotation_y = rotation_y + 1; if (rotation_y > 360) { rotation_y = 0; } this.transform.localRotation = Quaternion.Euler(rotation_x, rotation_y, rotation_z); } if (Input.GetAxis("rotate_h") > 0 || controllerInput.GetAxisRightThumbstickX() > 0) { if (rotation_y < 2) { rotation_y = 360; } rotation_y = rotation_y - 1; this.transform.localRotation = Quaternion.Euler(rotation_x, rotation_y, rotation_z); } }
/// <summary> /// 获得右侧摇杆的横向位移 /// </summary> /// <returns></returns> public float GetAxisRightThumbstickX() { #if UNITY_METRO && !UNITY_EDITOR return(controllerInput.GetAxisRightThumbstickX()); #else return(Input.GetAxis("RightHorizontal")); #endif }
void updateRotation() { //float v= Input.GetAxis("Right Stick X"); //float h =Input.GetAxis("Right Stick Y"); float h = controllerInput.GetAxisRightThumbstickY() * movementSpeed;// For bluetooth Xbox controller input Input.GetAxis("Right Stick X") float v = controllerInput.GetAxisRightThumbstickX() * movementSpeed; transform.Rotate(v, h, 0); }
/* private void translateRotateScale() * { * float moveHorizontal = MoveHorizontalSpeed * controllerInput.GetAxisLeftThumbstickX(); * float moveVertical = MoveVerticalSpeed * controllerInput.GetAxisLeftThumbstickY(); * this.transform.Translate(moveHorizontal, moveVertical, 0.0f); * * float rotateAroundY = RotateAroundYSpeed * controllerInput.GetAxisRightThumbstickX(); * float rotateAroundX = RotateAroundXSpeed * controllerInput.GetAxisRightThumbstickY(); * float rotateAroundZ = RotateAroundZSpeed * (controllerInput.GetAxisRightTrigger() - controllerInput.GetAxisLeftTrigger()); * this.transform.Rotate(rotateAroundX, -rotateAroundY, rotateAroundZ); * * if (controllerInput.GetButton(ControllerButton.DPadUp)) * this.transform.localScale = this.transform.localScale + (this.transform.localScale * ScaleSpeed * Time.deltaTime); * * if (controllerInput.GetButton(ControllerButton.DPadDown)) * this.transform.localScale = this.transform.localScale - (this.transform.localScale * ScaleSpeed * Time.deltaTime); * }*/ 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 adjustYaw() { // xbox control if (controllerInput.GetAxisRightThumbstickX() > 0) { transform.Rotate(Vector3.up * controllerInput.GetAxisRightThumbstickX() * 90 * Time.deltaTime); currentYaw += controllerInput.GetAxisRightThumbstickX() * 90 * Time.deltaTime; } else if (controllerInput.GetAxisRightThumbstickX() < 0) { transform.Rotate(Vector3.up * controllerInput.GetAxisRightThumbstickX() * 90 * Time.deltaTime); currentYaw += controllerInput.GetAxisRightThumbstickX() * 90 * Time.deltaTime; } // keyboard control if (Input.GetKey(KeyCode.D)) { transform.Rotate(Vector3.up * 45 * Time.deltaTime); currentYaw += 45 * Time.deltaTime; } if (Input.GetKey(KeyCode.A)) { transform.Rotate(Vector3.down * 45 * Time.deltaTime); currentYaw -= 45 * Time.deltaTime; } }
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); } }
void Update() { controllerInput.Update(); float mouseX = controllerInput.GetAxisRightThumbstickX(); // float mouseY = controllerInput.GetAxisRightThumbstickY(); // //mouseX= Input.GetAxis("Mouse X"); //mouseY= -Input.GetAxis("Mouse Y"); rotY += mouseX * mouseSensitivity * Time.deltaTime; rotX += mouseY * mouseSensitivity * Time.deltaTime; rotX = Mathf.Clamp(rotX, -clampAngle, clampAngle); Quaternion localRotation = Quaternion.Euler(rotX, rotY, 0.0f); transform.rotation = localRotation; }
void changeTransform() { float moveHorizontal = 0.0f, moveVertical = 0.0f, moveDepth = 0.0f; if (controllerInput.GetButton(ControllerButton.RightShoulder)) { moveDepth = MoveSpeed * controllerInput.GetAxisLeftThumbstickY(); } else { moveHorizontal = MoveSpeed * controllerInput.GetAxisLeftThumbstickX(); moveVertical = MoveSpeed * controllerInput.GetAxisLeftThumbstickY(); } var rotateAroundY = RotateSpeed * controllerInput.GetAxisRightThumbstickX(); transform.Translate(moveHorizontal, moveVertical, moveDepth); transform.Rotate(0, -rotateAroundY, 0); }
private void UpdateControls(Vector3 aim) { // Determine angle between user gaze vector and helicopter forward, in xz // plane Vector3 view = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z); Vector3 forward = new Vector3(transform.forward.x, 0, transform.forward.z); float angle = Vector3.Angle(view, forward); // Get current joypad axis values #if UNITY_EDITOR float hor = Input.GetAxis("Horizontal"); float ver = Input.GetAxis("Vertical"); float hor2 = Input.GetAxis("Horizontal2"); float ver2 = -Input.GetAxis("Vertical2"); float lt = Input.GetAxis("Axis9"); float rt = Input.GetAxis("Axis10"); bool buttonA = Input.GetKey(KeyCode.Joystick1Button0); bool buttonB = Input.GetKey(KeyCode.Joystick1Button1); bool fire = rt > 0.5f || buttonA; #else m_xboxController.Update(); float hor = m_xboxController.GetAxisLeftThumbstickX(); float ver = m_xboxController.GetAxisLeftThumbstickY(); float hor2 = m_xboxController.GetAxisRightThumbstickX(); float ver2 = m_xboxController.GetAxisRightThumbstickY(); float lt = m_xboxController.GetAxisLeftTrigger(); float rt = m_xboxController.GetAxisRightTrigger(); bool fire = rt > 0.5f; bool buttonA = m_xboxController.GetButton(ControllerButton.A); bool buttonB = m_xboxController.GetButton(ControllerButton.B); /* * float hor = Input.GetAxis("Horizontal"); * float ver = Input.GetAxis("Vertical"); * float axis3 = Input.GetAxis("Axis3"); * float lt = Mathf.Max(axis3, 0); * float rt = -Mathf.Min(axis3, 0); */ #endif // Any of the main axes (which are relative to orientation) pressed? bool movingThisFrame = (hor != 0) || (ver != 0); if (movingThisFrame && !m_movingLastFrame) { // Joypad was not pressed last frame, reorient based on current view position m_joypadLateralAxis = Vector3.Normalize(Camera.main.transform.right); m_joypadLongitudinalAxis = Vector3.Normalize(Camera.main.transform.forward); } m_movingLastFrame = movingThisFrame; // Apply longitudinal and lateral controls. Compute projection of joypad // lateral/longitudinal axes onto helicopter's. float joypadLongitudinalToHeliLongitudinal = Vector3.Dot(m_joypadLongitudinalAxis, transform.forward); float joypadLongitudinalToHeliLateral = Vector3.Dot(m_joypadLongitudinalAxis, transform.right); float joypadLateralToHeliLongitudinal = Vector3.Dot(m_joypadLateralAxis, transform.forward); float joypadLateralToHeliLateral = Vector3.Dot(m_joypadLateralAxis, transform.right); m_playerControls.longitudinal = joypadLongitudinalToHeliLongitudinal * ver + joypadLateralToHeliLongitudinal * hor; m_playerControls.lateral = joypadLongitudinalToHeliLateral * ver + joypadLateralToHeliLateral * hor; // Helicopter rotation m_playerControls.rotational = hor2; // Altitude control (trigger axes each range from 0 to 1) m_playerControls.altitude = ver2; // Gun if (fire && (Time.time - m_gunLastFired >= GUN_FIRE_PERIOD)) { FireGun(aim); } }