- Home /
Changing Time.fixedDeltaTime to create slowmotion messes up with physics.
I am trying to create a simple slow motion changing timeScale but I have some issues.
First I used Time.fixedDeltaTime so I can properly watch the slowmotion itself, but is changes something with physics. The next Gif shows a ball getting a force and passing through a tube without slowmotion and then with slowmotion.
I followed Brackeys video about slow motion but it ends to the same problem.
void ToggleSlowMotion()
{
slow = !slow;
if(slow == true)
{
Time.timeScale = slowdownFactor;
Time.fixedDeltaTime = Time.fixedDeltaTime * slowdownFactor;
}
else
{
Time.timeScale = 1;
Time.fixedDeltaTime = Time.timeScale * 0.02f;
}
}
Answer by Edy · Aug 31, 2021 at 02:40 PM
Do not modify Time.fixedDeltaTime. The advice of doing so in the Unity manual is a very bad practice and should be removed.
The correct way for implementing the slow motion effect and keeping the physics behavior unchanged is changing Time.deltaTime only. Also enable Rigidbody.interpolation to keep the visual motion smooth.
Time.fixedDeltaTime also defines the physics rate, that is, the rate of physics calculations per second. Modifying this value forcefully changes the behavior of the physics simulation. Only change Time.fixedDeltaTime when you have a very good reason to do so, and definitely a visual slow motion effect is not a good reason.
More details and examples:
https://forum.unity.com/threads/adjusting-time-fixeddeltatime-by-time-timescale.869491/#post-6789077
Your answer
Follow this Question
Related Questions
2nd independent deltaTime and timeScale variables, or a way to mimic this? 1 Answer
Stabilizing ragdolls in slow motion 0 Answers
How to have realtime months/years pass in seconds 1 Answer
Need help affecting 2d jump with UnscaledDeltatime 0 Answers
Is there an equivalent of Time.frameCount for physics updates? 1 Answer