void Update() { // Exit Sample // if (Input.GetKey(KeyCode.Escape)) // { // Application.Quit(); //#if UNITY_EDITOR // UnityEditor.EditorApplication.isPlaying = false; //#endif // } // Hide and lock cursor when right mouse button pressed if (Input.GetMouseButtonDown(1)) { //Cursor.lockState = CursorLockMode.Locked; } // Unlock and show cursor when right mouse button released if (Input.GetMouseButtonUp(1)) { //Cursor.visible = true; //Cursor.lockState = CursorLockMode.None; } // Rotation if (Input.GetMouseButton(1)) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; // Speed up movement when shift key held if (Input.GetKey(KeyCode.LeftShift)) { translation *= 10.0f; } // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) boost += Input.mouseScrollDelta.y * 0.2f; translation *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void Update() { //Put cursor back into lock mode if (Cursor.lockState == CursorLockMode.None) { if (Input.GetMouseButton(0) || Input.GetMouseButton(1)) { Cursor.lockState = CursorLockMode.Locked; Time.timeScale = 1; } if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } } else { getMouseRotation(); if (Input.GetKey(KeyCode.Escape)) { Cursor.lockState = CursorLockMode.None; Time.timeScale = 0; } } // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; var keyRotation = GetMouseTranslationKeybing() * Time.deltaTime; m_TargetCameraState.yaw += keyRotation.x; m_TargetCameraState.pitch += keyRotation.y; // Speed up movement when shift key held if (Input.GetKey(KeyCode.LeftShift)) { translation *= 5.0f; } // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) boost += Input.mouseScrollDelta.y * 0.2f; translation *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void Update() { Vector3 translation = Vector3.zero; // Exit Sample if (Keyboard.current[Key.Escape].isPressed) { Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } // Hide and lock cursor when right mouse button pressed if (Mouse.current.rightButton.wasPressedThisFrame) { Cursor.visible = false; Cursor.lockState = CursorLockMode.Confined; } // Unlock and show cursor when right mouse button released if (Mouse.current.rightButton.wasReleasedThisFrame) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } // Rotation if (Mouse.current.rightButton.isPressed) { Move = controls.Player.Move.ReadValue <Vector2>(); var mouseMovement = new Vector2(Move.x, Move.y * -1) * 0.05f; // Vector 2! var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // Translation translation = GetInputTranslationDirection() * Time.deltaTime * 2; // Speed up movement when shift key held if (Keyboard.current[Key.LeftShift].isPressed) { translation *= 2.5f; } m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void Update() { Vector3 translation = Vector3.zero; #if ENABLE_LEGACY_INPUT_MANAGER // Exit Sample if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } // Hide and lock cursor when right mouse button pressed if (Input.GetMouseButtonDown(0)) { lastPos = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); } // Rotation if (Input.GetMouseButton(0) || Input.GetMouseButton(1)) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // Translation translation = GetInputTranslationDirection() * Time.deltaTime; // Speed up movement when shift key held if (Input.GetKey(KeyCode.LeftShift)) { translation *= 10.0f; } // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) boost += Input.mouseScrollDelta.y * 0.2f; translation *= Mathf.Pow(2.0f, boost); #elif USE_INPUT_SYSTEM // TODO: make the new input system work #endif m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void LateUpdate() { // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
private void LateUpdate() { transform.rotation = Quaternion.Euler(_cameraAngle, 0f, 0f); Vector3 desieredCameraPosition = GetCameraPosition(); _interpolatingCameraState.LerpTowards(desieredCameraPosition, _positionLerpTime * Time.deltaTime); _interpolatingCameraState.UpdateTransform(transform); }
void Update() { Vector3 translation = Vector3.zero; #if ENABLE_LEGACY_INPUT_MANAGER // Hide and lock cursor when right mouse button pressed if (Input.GetMouseButtonDown(1)) { Cursor.lockState = CursorLockMode.Locked; } // Unlock and show cursor when right mouse button released if (Input.GetMouseButtonUp(1)) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } // Rotation if (Input.GetMouseButton(1)) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // Translation translation = GetInputTranslationDirection() * Time.deltaTime; // Speed up movement when shift key held //if (Input.GetKey(KeyCode.LeftShift)) //{ // //translation *= 10.0f; //} // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) //boost += Input.mouseScrollDelta.y * 0.2f; translation *= Mathf.Pow(2.0f, boost); #elif USE_INPUT_SYSTEM // TODO: make the new input system work #endif m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void Update() { // Hide and lock cursor when right mouse button pressed if (IsRightMouseButtonDown()) { Cursor.lockState = CursorLockMode.Locked; } // Unlock and show cursor when right mouse button released if (IsRightMouseButtonUp()) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } // Rotation if (IsCameraRotationAllowed()) { var mouseMovement = GetInputLookRotation() * Time.deltaTime * 5; if (invertY) { mouseMovement.y = -mouseMovement.y; } var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; // Speed up movement when shift key held if (IsBoostPressed()) { translation *= 10.0f; } // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) boost += GetBoostFactor(); translation *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void Update() { //-- exit play mode if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } //-- Hide+lock cursor while RMB pressed if (Input.GetMouseButtonDown(1)) { Cursor.lockState = CursorLockMode.Locked; // locked to center of view, invisible } if (Input.GetMouseButtonUp(1)) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } //-- Camera rotation if (Input.GetMouseButton(1)) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")); var mouseSensitivityFactor = MouseSensitivityCurve.Evaluate(mouseMovement.magnitude); _targetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; _targetCameraState.pitch -= mouseMovement.y * mouseSensitivityFactor; } //-- Camera translation (Shift - increase speed) var shift = GetInputTranslationDirection() * Time.deltaTime; if (Input.GetKey(KeyCode.LeftShift)) { shift *= 10.0f; } //-- Movement boost factor (controlled by mouse wheel) Boost += Input.mouseScrollDelta.y * 0.2f; shift *= Mathf.Pow(2.0f, Boost); _targetCameraState.Translate(shift); //-- interpolation var positionLerpFactor = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / PositionLerpTime) * Time.deltaTime); var rotationLerpFactor = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / PositionLerpTime) * Time.deltaTime); _interpolatingCameraState.LerpTowards(_targetCameraState, positionLerpFactor, rotationLerpFactor); _interpolatingCameraState.UpdateTransform(transform); }
void FixedUpdate() { if (m_keyboard == null) { return; } if (m_keyboard.uKey.isPressed) { ResetCamera(); return; } var touches = m_screen.GetTouches(); // Rotation if (IsMouseDragged(m_mouse, false)) { UpdateTargetCameraStateFromInput(m_mouse.delta.ReadValue()); } else if (touches.Count() == 1) { var activeTouches = touches.ToArray(); UpdateTargetCameraStateFromInput(activeTouches[0].delta); } // Rotation from joystick if (m_gamepad?.leftStick != null) { UpdateTargetCameraStateFromInput(m_gamepad.leftStick.ReadValue()); } // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; // Speed up movement when shift key held if (m_keyboard.leftShiftKey.isPressed) { translation *= 10.0f; } translation *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void FixedUpdate() { if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } if (Input.GetMouseButtonDown(1)) { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } if (Input.GetMouseButtonUp(1)) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } if (Input.GetMouseButton(1)) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } var translation = GetInputTranslationDirection() * Time.deltaTime; if (Input.GetKey(KeyCode.LeftShift)) { translation *= 10.0f; } boost += Input.mouseScrollDelta.y * 0.2f; translation *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(translation); //characterController. //Move(translation); var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
private void Update() { float dt = Time.deltaTime; if (Keyboard.current.escapeKey.wasPressedThisFrame) { #if UNITY_EDITOR EditorApplication.isPlaying = false; #endif Application.Quit(); } if (Mouse.current.rightButton.wasPressedThisFrame) { Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; } if (Mouse.current.rightButton.wasReleasedThisFrame) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } // rotation if (Mouse.current.rightButton.isPressed) { Vector2 mouseMovement = Mouse.current.delta.ReadValue() * 0.02f; mouseMovement.y = mouseMovement.y * (invertY ? 1 : -1); float mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); targetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; targetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // translation Vector3 translation = GetInputTranslationDirection() * dt; if (Keyboard.current.leftShiftKey.isPressed) { translation *= 10.0f; } // modify movement by a boost factor boost += Mouse.current.scroll.y.ReadValue() * 0.002f; translation *= Mathf.Pow(2.0f, boost); targetCameraState.Translate(translation); interpolatingCameraState.LerpTowards(targetCameraState, positionLerpTime, rotationLerpTime, dt); interpolatingCameraState.UpdateTransform(transform); }
public void NotifyCameraMovement(Vector3 direction) { direction *= Time.deltaTime; direction *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(direction); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void Update() { // Exit Sample if (dontMove) { return; } if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } // Hide and lock cursor when right mouse button pressed if (Input.GetMouseButtonDown(1)) { Cursor.lockState = CursorLockMode.Locked; } // Unlock and show cursor when right mouse button released if (Input.GetMouseButtonUp(1)) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } // Rotation if (Input.GetMouseButton(1)) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } m_TargetCameraState.distance -= Input.mouseScrollDelta.y * distanceSteps; m_TargetCameraState.targetPosition = targetPosition; // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void FPSMovement() { // Use LSHIFT to toggle control if (Input.GetKeyDown(KeyCode.LeftShift)) { Cursor.lockState = CursorLockMode.Locked; } // Unlock and show cursor when right mouse button released if (Input.GetKeyUp(KeyCode.LeftShift)) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } if (Input.GetKey(KeyCode.LeftShift)) { // Rotation var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; //// Speed up movement when shift key held //if (Input.GetKey(KeyCode.LeftShift)) { // translation *= 10.0f; //} // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) boost += Input.mouseScrollDelta.y * 0.2f; translation *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); } ///// }
private void Update() { if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } // Hide and lock cursor when right mouse button pressed if (Input.GetMouseButtonDown(1)) { Cursor.lockState = CursorLockMode.Locked; } // Unlock and show cursor when right mouse button released if (Input.GetMouseButtonUp(1)) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } // Rotation if (Input.GetMouseButton(2)) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); _targetCameraState.Yaw += mouseMovement.x * mouseSensitivityFactor; _targetCameraState.Degree += mouseMovement.y * mouseSensitivityFactor; } // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; // Speed up movement when shift key held if (Input.GetKey(KeyCode.LeftShift)) { translation *= 10.0f; } boost += Input.mouseScrollDelta.y * 0.2f; translation *= Mathf.Pow(2.0f, boost); _targetCameraState.Translate(translation); var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); _interpolatingCameraState.LerpTowards(_targetCameraState, positionLerpPct, rotationLerpPct); _interpolatingCameraState.UpdateTransform(transform); }
void FixedUpdate() { if (Keyboard.current.uKey.isPressed) { ResetCamera(); return; } // Rotation if (IsMouseDragged(Mouse.current, false)) { UpdateTargetCameraStateFromInput(Mouse.current.delta.ReadValue()); } else if (IsMouseDragged(RemoteInput.RemoteMouse, false)) { UpdateTargetCameraStateFromInput(RemoteInput.RemoteMouse.delta.ReadValue()); } else if (UnityEngine.InputSystem.EnhancedTouch.Touch.activeTouches.Count == 1) { UpdateTargetCameraStateFromInput(UnityEngine.InputSystem.EnhancedTouch.Touch.activeTouches[0].delta); } // Rotation from joystick if (Gamepad.all.Count > 0) { UpdateTargetCameraStateFromInput(Gamepad.all[Gamepad.all.Count - 1].leftStick.ReadValue()); } // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; // Speed up movement when shift key held if (Keyboard.current.leftShiftKey.isPressed) { translation *= 10.0f; } translation *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void LateUpdate() { if (Input.GetKeyDown(KeyCode.Escape)) { if (settings.activeInHierarchy) { settings.SetActive(false); QuitButton.SetActive(false); } else { settings.SetActive(true); QuitButton.SetActive(true); } Back.SetActive(false); } if (Input.GetMouseButton(1)) { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; RotX = Input.GetAxis("Mouse X"); RotY = Input.GetAxis("Mouse Y"); var mouseMovement = new Vector2(RotX, RotY * (invertY ? 1 : -1)); //var mouseSenseFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude) * mouseSenseValue; var mouseSenseFactor = mouseSenseValue; targetState.yaw += mouseMovement.x * mouseSenseFactor; targetState.pitch += mouseMovement.y * mouseSenseFactor; var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); InterpolateCameraState.LerpTowards(targetState, positionLerpPct, rotationLerpPct); InterpolateCameraState.UpdateTransform(transform); var characterRotation = transform.rotation; characterRotation.x = 0; characterRotation.z = 0; playerObject.transform.rotation = characterRotation; } else { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } }
void Update() { // Exit Sample if (controls.Game.Quit.ReadValue <float>() == 1) { Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } // Rotation if (controls.Camera.Aim.ReadValue <float>() == 1) { var mouseMovement = new Vector2(controls.Camera.Rotation.ReadValue <Vector2>().x, controls.Camera.Rotation.ReadValue <Vector2>().y *(invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude / magnitudeForMaxSensitivity); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; // Speed up movement when shift key held if (controls.Camera.SpeedUp.ReadValue <float>() == 1) { translation *= speedUpMultiplier; } // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) boost += controls.Camera.Boost.ReadValue <float>() * boostInputMultiplier; boost = Mathf.Clamp(boost, minBoost, maxBoost); translation *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
private void GetInputRotation() { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(BoomArm.transform); }
private void Update() { // Hide and lock cursor when right mouse button pressed if (Input.GetMouseButtonDown(1)) { Cursor.lockState = CursorLockMode.Locked; } else if (Input.GetMouseButtonUp(1)) // Unlock and show cursor when right mouse button released { Cursor.lockState = CursorLockMode.None; } // Rotation if (Input.GetMouseButton(1)) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); targetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; targetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; // Speed up movement if (Input.GetKey(KeyCode.LeftControl)) { translation *= 10.0f; } // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) boost += Input.mouseScrollDelta.y * 0.2f; translation *= Mathf.Pow(2.0f, boost); targetCameraState.Translate(translation); // Framerate independent interp var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); interpolatingCameraState.LerpTowards(targetCameraState, positionLerpPct, rotationLerpPct); interpolatingCameraState.UpdateTransform(transform); }
void Update() { // Hide and lock cursor when right mouse button pressed if (Input.GetMouseButtonDown(1)) { Cursor.lockState = CursorLockMode.Locked; } // Unlock and show cursor when right mouse button released if (Input.GetMouseButtonUp(1)) { Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } // Rotation if (Input.GetMouseButton(1)) { Vector2 mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (m_InvertY ? 1 : -1)); float mouseSensitivityFactor = m_MouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // Translation Vector3 translation = GetInputTranslationDirection() * Time.deltaTime; // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) translation *= m_Boost; m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time float positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / m_PositionLerpTime) * Time.deltaTime); float rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / m_RotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); m_Compass.position = transform.position + m_CompassPositionOffset; m_Compass.localEulerAngles = -transform.eulerAngles; }
void Update() { // Exit Sample if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } // Rotation if (Input.GetMouseButton(1)) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY? 1: -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; // Speed up movement when shift key held if (Input.GetKey(KeyCode.LeftShift)) { translation *= 10.0f; } //boost += Input.mouseScrollDelta.y * 0.2f; translation *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void Update() { // Translation // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
private void FixedUpdate() { // Tracked Device if (inputPosition.HasValue && inputRotation.HasValue) { transform.position = inputPosition.Value; transform.rotation = inputRotation.Value; return; } UpdateTargetCameraStateDirection(inputMovement); UpdateTargetCameraStateFromInput(inputLook); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
public void GameUpdate() { if (ActiveControl) { // Rotation if (Input.GetMouseButton(1)) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; // Speed up movement when shift key held if (Input.GetKey(KeyCode.LeftShift)) { translation *= 10.0f; } // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) boost += Input.mouseScrollDelta.y * 0.2f; translation *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); } }
void Update() { Vector3 translation = Vector3.zero; #if ENABLE_LEGACY_INPUT_MANAGER // Exit Sample if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; // Translation translation = GetInputTranslationDirection() * Time.deltaTime; translation *= Mathf.Pow(2.0f, speed); #elif USE_INPUT_SYSTEM // TODO: make the new input system work #endif m_TargetCameraState.Translate(translation); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void Update() { // Rotation var mouseMovement = GetInputLookRotation() * 0.1f; mouseMovement.y = -mouseMovement.y; m_TargetCameraState.yaw += mouseMovement.x; m_TargetCameraState.pitch += mouseMovement.y; // Translation var translation = GetInputTranslationDirection() * Time.deltaTime; var deltaY = verticalMovementAction.ReadValue <Vector2>().y *Time.deltaTime; // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) boost += GetBoostFactor(); float currentBoostFactor = Mathf.Pow(2.0f, boost); // Speed up movement when shift key held if (IsBoostPressed()) { currentBoostFactor *= 10.0f; } translation *= currentBoostFactor; deltaY *= currentBoostFactor; m_TargetCameraState.Translate(translation, deltaY); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void Update() { Vector3 translation = Vector3.zero; // Exit Sample if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif } if (Input.GetMouseButton(1) || !rightClickToLook || (Input.GetKey(KeyCode.LeftAlt) && Input.GetMouseButton(0))) { var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; } // Translation translation = GetInputTranslationDirection() * Time.unscaledDeltaTime; // Modify movement by a boost factor (defined in Inspector) translation *= Mathf.Pow(2.0f, boost); m_TargetCameraState.Translate(translation, bounds); // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.unscaledDeltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.unscaledDeltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }
void Update() { // Exit Sample if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); #if UNITY_EDITOR //UnityEditor.EditorApplication.isPlaying = false; #endif } // Rotation var mouseMovement = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y") * (invertY ? 1 : -1)); var mouseSensitivityFactor = mouseSensitivityCurve.Evaluate(mouseMovement.magnitude); m_TargetCameraState.yaw += mouseMovement.x * mouseSensitivityFactor; m_TargetCameraState.pitch += mouseMovement.y * mouseSensitivityFactor; // Translation //var translation = GetInputTranslationDirection() * Time.deltaTime; // Modify movement by a boost factor (defined in Inspector and modified in play mode through the mouse scroll wheel) /*boost += Input.mouseScrollDelta.y * 0.2f; * translation *= Mathf.Pow(2.0f, boost); * * m_TargetCameraState.Translate(translation);*/ // Framerate-independent interpolation // Calculate the lerp amount, such that we get 99% of the way to our target in the specified time var positionLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / positionLerpTime) * Time.deltaTime); var rotationLerpPct = 1f - Mathf.Exp((Mathf.Log(1f - 0.99f) / rotationLerpTime) * Time.deltaTime); m_InterpolatingCameraState.LerpTowards(m_TargetCameraState, positionLerpPct, rotationLerpPct); m_InterpolatingCameraState.UpdateTransform(transform); }