I want my player to deaccelerate when he stop not just stop in place. Here is my code:
public override Vector3 Move(MovementManager manager, Vector2 input, bool jump, bool isCrouching)
{
float speed = isCrouching ? CrouchSpeed : MoveSpeed;
Vector3 velocity = manager.Velocity;
float currentVelocity = new Vector3(velocity.x, 0, velocity.z).magnitude;
Vector3 moveDirection = Vector3.zero;
if (Mathf.Abs(input.x) > 0 || Mathf.Abs(input.y) > 0)
{
moveDirection = new Vector3(input.x, 0, input.y);
moveDirection = manager.transform.TransformDirection(moveDirection);
if(input.y > 0)
moveDirection *= input.y;
LastMoveDirection = moveDirection;
if (IsWalkSpeed) currentVelocity += (Acceleration * .4f) * Time.fixedDeltaTime;
else currentVelocity += Acceleration * Time.fixedDeltaTime;
//if (currentVelocity > MaxSpeed) currentVelocity = MaxSpeed;
if (currentVelocity > speed) currentVelocity = speed;
return moveDirection.normalized * currentVelocity * Time.fixedDeltaTime;
}
else
{
currentVelocity -= Deacceleration * Time.fixedDeltaTime;
currentVelocity = Mathf.Max(currentVelocity, 0);
return LastMoveDirection.normalized * currentVelocity * Time.fixedDeltaTime;
}
}
Deaccelerationis too large? \$\endgroup\$