I need my participant to deaccelerate when he cease not simply cease in place.
Right here is my code:
public override Vector3 Transfer(MovementManager supervisor, Vector2 enter, bool bounce, bool isCrouching)
{
float pace = isCrouching ? CrouchSpeed : MoveSpeed;
Vector3 velocity = supervisor.Velocity;
float currentVelocity = new Vector3(velocity.x, 0, velocity.z).magnitude;
Vector3 moveDirection = Vector3.zero;
if (Mathf.Abs(enter.x) > 0 || Mathf.Abs(enter.y) > 0)
{
moveDirection = new Vector3(enter.x, 0, enter.y);
moveDirection = supervisor.rework.TransformDirection(moveDirection);
if(enter.y > 0)
moveDirection *= enter.y;
LastMoveDirection = moveDirection;
if (IsWalkSpeed) currentVelocity += (Acceleration * .4f) * Time.fixedDeltaTime;
else currentVelocity += Acceleration * Time.fixedDeltaTime;
//if (currentVelocity > MaxSpeed) currentVelocity = MaxSpeed;
if (currentVelocity > pace) currentVelocity = pace;
return moveDirection.normalized * currentVelocity * Time.fixedDeltaTime;
}
else
{
currentVelocity -= Deacceleration * Time.fixedDeltaTime;
currentVelocity = Mathf.Max(currentVelocity, 0);
return LastMoveDirection.normalized * currentVelocity * Time.fixedDeltaTime;
}
}