- Home /
Physics calculations vs TimeScale vs FixedDeltaTime
Hello everybody!
I've looked at the documentation and searched for quite a few posts without a solution..
PROBLEM: it's possible modify physics timeScale & fixedDeltaTime (Pause Game) without causing all the hingeJoints gone crazy? :(
If i only change timeScale (not fixedDeltaTime) all stuff movement in fixedUpdate() like camera, characters, etc... moves choppy in slowtime.
If i change timeScale and proportionally fixedDeltaTime (as Unity documentation recommends) ...all stuff moves smoothly and nice in slowtime BUT physics on hingeJoints gets an unstable shake because change of "gravity vs physics calculations (solver)" not working as expected.
Please, any advice? Thanks!
float xTime = 1.0f;
void Update(){
Time.timeScale = xTime;
Time.fixedDeltaTime = 0.01F * xTime;
}
public void pauseTime(){
xTime = 0.0000001f;
}
public void slowTime(){
xTime = 0.2f;
}
public void normalTime(){
xTime = 1.0f;
}
Answer by Daemonhahn · Feb 21, 2017 at 05:01 PM
never change fixed delta time, fixed delta time is meant to be used by the entire physics engine to work out physics calculations and doing this will throw everything off.
Setting the "fixedDeltaTime" according to timescale is recommended by the Unity documentation. If you didn't ..you will get a choppy effect.
Taking the fixedDeltaTime to 0.005f (ins$$anonymous$$d of 0.2f by default) reduces the issue. It was very slow and not enough to calculate the physiques in the hingeJoints in time to compensate for gravity. I have also opted to separate the timescale change (applied in function Update) from the proportional setting of fiexDeltaTime (applied in FixedUpdate function)
I'm doing tests to check the reaction of the physics engine to all these variables. I also checked to increase in ProjectSettings / Physics the speed of the solver, iterations, etc ... (does not seem to matter much).
The key seems to be in the fixedDeltaUpdate, in finding a value that moves everything correctly without consu$$anonymous$$g the performance.
For "pause" case (timeScale = 0) it's ok, without changing fixedDeltaTime no issues appear. And as there are no objects in motion during the pause they can not see moving choppy.
But my question is about solving when physics I want to get a superslowtime effect with things moving, altering timescale without the physics going crazy.