- Home /
How to use Time.fixedDeltaTime for slow motion?
if (coll.gameObject.name == "TrailSlow") {
Time.timeScale = 0.5F;
}
else{
Time.timeScale = 1F;
}
I have written this script that makes the game work at half the speed whenever a ball collides with another object. I have noticed that once it is at half speed the movements are not smooth.
I understand that I have to implement Time.fixedDeltaTime to make things smoother, could someone show me how to implement them to the code above?
I have tried myself. The game goes smooth at slow motion but after a few more hits (back and forth between timescale 1 and 0.5F) the game starts jittering at like 3 fps. I know I am doing it wrong somewhere!
Try setting the interpolation variable of your rigidbodies to interpolate.
It might be some other code of yours which may be causing this issue.. like you are destroying too many objects and instantiating them which may cause garbage collection to happen and causing the lag?
If you lower timeScale it is recommended to also lower Time.fixedDeltaTime by the same amount.
Don't forget to put it back again.
Answer by Ignacitus1111 · Jun 06, 2018 at 12:35 AM
Like this:
void FixedUpdate() //Just in case it's still laggy put FixedUpdate, but try Update if you want
{
Time.timeScale = 0.5f;
Time.fixedDeltaTime = Time.timeScale * 0.02f;
}