Make the player faster when game is in slow motion

Hello!!

I’m trying to make the player faster when the game is in slow motion.

void Update()
{
    if (Input.GetKeyDown(KeyCode.E))
    {
        Time.timeScale = slowdownFactor;
        Time.fixedDeltaTime = 0.02F * Time.timeScale;
    }
}

void FixedUpdate()
{
    // player is a rigidbody2D
    float h = Input.GetAxisRaw("Horizontal");

    float targetVelocityX = h * maxSpeed * (1 / Time.timeScale);

    float smoothTime = .1f;

    targetVelocityX = Mathf.SmoothDamp(player.velocity.x, targetVelocityX, ref velocityXSmoothing, smoothTime);

    player.velocity = new Vector2(targetVelocityX, player.velocity.y);
}

I think the problem is related with Mathf.SmoothDamp. When the time scale changes, the max speed is scaled as well, thus it seems that the player is teleported instead of keeping the same velocity.

Any ideas about to keep the same velocity using SmoothDamp?

Thanks!!

Modify Time.timeScale only. Don’t touch Time.fixedDeltaTime, as it affects the physics causing unexpected effects.