Question by
nantoaqui · Dec 18, 2017 at 07:39 AM ·
jittersmoothdampslowmotion
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!!
Comment
Answer by Edy · Dec 21, 2017 at 09:41 AM
Modify Time.timeScale only. Don't touch Time.fixedDeltaTime, as it affects the physics causing unexpected effects.
Your answer
![](https://koobas.hobune.stream/wayback/20220612144803im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Hinge Joint issue 0 Answers
Character Controller jittering with other colliders 0 Answers
How can I slow the movement of a single rigidbody2D? 2 Answers
How to fix the player/collision glitch? 0 Answers
SmoothDamp not working perfectly? 1 Answer