I want my player to stop for a split of a second when changing direction instead of just continuing to move. I control my player with virtual joystick ( it is an androidn game) and currently I have a behavior where your speed is determent partly by position of a joystick ( the closer it is to the middle you move slower). The problem is I can still change direction rally fast so my player doesn’t slow down when I start moving backwards after moving forward. Here is my code:
public override Vector3 Move(MovementManager manager, Vector2 input, bool jump, bool isCrouching)
{
float speed = isCrouching ? CrouchSpeed : MoveSpeed;
Input = input;
if (Mathf.Abs(input.x) > 0 || Mathf.Abs(input.y) > 0)
{
moveDirection = new Vector3(input.x, 0, input.y);
moveDirection = manager.transform.TransformDirection(moveDirection);
LastMoveDirection = moveDirection;
if (IsWalkSpeed) currentVelocity += (Acceleration * .4f) * Time.fixedDeltaTime;
else currentVelocity += Acceleration * Time.fixedDeltaTime;
if (currentVelocity > speed) currentVelocity = speed;
currentVelocity *= Mathf.Abs(input.y) + Mathf.Abs(input.x);
}
else
{
currentVelocity -= Deacceleration * Time.fixedDeltaTime;
currentVelocity = Mathf.Max(currentVelocity, 0);
}
return LastMoveDirection.normalized * currentVelocity * Time.fixedDeltaTime;
}