private Vector3 ApplyGravity() { if (!collision.OnGround && gravityOn) { return(gravityModule.GetGravity() * Time.deltaTime); } return(Vector3.zero); }
// Update is called once per frame void Update() { float x = Input.GetAxisRaw("Horizontal"); float z = Input.GetAxisRaw("Vertical"); Vector3 move = transform.right * x + transform.forward * z; if (z < 0) { StopRunning(); } RotatePlayerModel(x, z, move); if (move.magnitude > 0) { if (!_povScript.IsFirstPerson()) { float targetAngle = _thirdPersonCamera.transform.eulerAngles.y; float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref _turnSmoothVelocity, _turnSmoothTime); transform.localRotation = Quaternion.Euler(0f, angle, 0f); } _smoothSpeed = Mathf.Lerp(_smoothSpeed, _maxSpeed, _speedInterpolation * Time.deltaTime); _controller.Move(move.normalized * _smoothSpeed * Time.deltaTime); } else { StopRunning(); _smoothSpeed = Mathf.Lerp(_smoothSpeed, 0, _speedInterpolation * Time.deltaTime); _controller.Move(move.normalized * _smoothSpeed * Time.deltaTime); } if (Input.GetButtonDown("Jump") && _gravityScript.IsGrounded()) { _gravityScript.SetVelocity(Mathf.Sqrt(-JumpVelocity * _gravityScript.GetGravity())); } if (Input.GetKeyDown(KeyCode.LeftShift)) { IsRunning = !IsRunning; _maxSpeed = IsRunning ? MaxRunSpeed : MaxWalkSpeed; } }