private void GroundMove() { Vector3 wishDir; if (!_wishToJump) { _playerVelocity = PlayerMovementCalculations.CalculateFricition(_playerVelocity, _runDeacceleration, _groundFriction, _controller.isGrounded, 1); } else { _playerVelocity = PlayerMovementCalculations.CalculateFricition(_playerVelocity, _runDeacceleration, _groundFriction, _controller.isGrounded, 0); } SetMovementDirection(); wishDir = new Vector3(_movementCommand.right, 0, _movementCommand.forward); wishDir = transform.TransformDirection(wishDir); wishDir.Normalize(); var wishSpeed = wishDir.magnitude; wishSpeed *= _moveSpeed; _playerVelocity = PlayerMovementCalculations.CalculateAcceleration(_playerVelocity, wishDir, wishSpeed, _runAcceleration); _playerVelocity.y = -_gravity * Time.deltaTime; if (_wishToJump) { _playerVelocity.y = _jumpAcceleration; _wishToJump = false; } }
public void CalculateFriction_Air() { var playerVelocity = new Vector3(0f, -0.2f, 7f); float runDeacceleration = 10f; float groundFriction = 6f; float baseFriction = 1f; bool isGrounded = false; Vector3 result = PlayerMovementCalculations.CalculateFricition( playerVelocity, runDeacceleration, groundFriction, isGrounded, baseFriction ); var expected = new Vector3(0f, -0.2f, 7f); Assert.AreEqual(expected, result); }