private void Update() { //movement _currentKeys = InputUtil.GetIfKeysHeld(_controls); UpdateAnimator(); Vector3 targetMoveVector = GetMovementVector(_currentKeys, MoveForce); _currentMoveVector = Vector3.SmoothDamp(_currentMoveVector, targetMoveVector, ref _internalVelocity, _smoothTime); targetMoveVector = GravityVector3 + _currentMoveVector; OriginShifter.MoveOriginBy(targetMoveVector * Time.deltaTime); }
// Update is called once per frame void Update() { //cursor settings if (_lockCursor) { Cursor.lockState = CursorLockMode.Locked; } if (_cursorVisible) { Cursor.visible = false; } //cam //TODO: refactor out //ripped from https://forum.unity.com/threads/a-free-simple-smooth-mouselook.73117/ //and https://catlikecoding.com/unity/tutorials/movement/orbit-camera/ if (_rawMouseInput) { _inputs.x = Input.GetAxisRaw("Mouse X"); _inputs.y = Input.GetAxisRaw("Mouse Y"); } else { _inputs.x = Input.GetAxis("Mouse X"); _inputs.y = Input.GetAxis("Mouse Y"); } if (_camOffsetDistance < 0) { _inputs.y *= -1; } Vector2 mouseInput = new Vector2(_inputs.y * _mouseSensitivityY, _inputs.x * _mouseSensitivityX); _camTargetRotations += mouseInput; if (_isYClamped) { _camTargetRotations.x = Mathf.Clamp(_camTargetRotations.x, _cameraYMin, _cameraYMax); } if (_isXClamped) { _camTargetRotations.y = Mathf.Clamp(_camTargetRotations.y, _cameraXMin, _cameraXMax); } if (_cameraIsOrbiting) { Quaternion lookRotation = Quaternion.Euler(_camTargetRotations); Vector3 lookDirection = lookRotation * Vector3.forward; Vector3 lookPosition = _cameraPositionFocus.position - (lookDirection * _camOffsetDistance) - _camOffsetVector; _camera.transform.SetPositionAndRotation(lookPosition, lookRotation); } else { //I'm aware you're not supposed to edit the rotation directly, but the camera is not going to use physics _camera.transform.rotation = Quaternion.Euler(-_camTargetRotations.y, _camTargetRotations.x, 0); } // Jump if (Input.GetKeyDown("space") && isGrounded) { _rigidbody.AddForce(Vector3.up * jumpSpeed, ForceMode.Impulse); isGrounded = false; } //movement _currentKeys = InputUtil.GetIfKeysHeld(_controls); PlayerMovement(); }