- Home /
How to keep physics consistent?
To start of, my game is pretty physics heavy, as it's a racing game with high speed moving vehicles. Also, it runs on iPhone/Android, so I have to find a good compromise.
My first question is regarding the "Fixed Timestep" and "Maximum Allowed Timestep" settings. My current settings are as follow:
Fixed Timestep: 0.02 Max Allowed: 0.1
I can get away with 0.03 but sometimes, the wheel colliders go through the ground, so I have to add Sphere Colliders to my wheels as well to keep them from doing it. I went back down to 0.02 because my frame-rate is still over 45-55 even at that value, so I might as well have better physics simulations if I can afford it. I was wondering, for you guys that are developing physics heavy games on mobile devices, what settings seem to work best for you?
My second question is about physics calculations in FixedUpdate. I have been developing my game, for the most part, at a Fixed Timestep of 0.03, and now that I lowered it to 0.02, my physics calculation are "stronger"...for example, I have a "Spring" function that basically does this in Fixed Update:
springPower = 5000f; transform.rigidbody.AddRelativeForce( ForceDir * springPower, ForceMode.Impulse );
With a Timestep of 0.02, that force is stronger and pushes my vehicle higher into the sky then with a Timestep of 0.03, which is normal behavior correct? How can I force that calculation to always apply the same amount of force regardless of the Timestep value?
That's it, thanks for your time guys!
Stephane
there is no way short of running it in update maybe and using time.deltatime.
Answer by ThePunisher · Nov 20, 2012 at 12:30 AM
Can't you multiply by the Time.fixedDeltaTime so that only a certain amount of that force is applied based on the delta. So a larger delta between time steps applies more force per step and a smaller time step applies less. Does that make sense or did I just lose my mind? Sorry I'm distracted right now :(
Well I thought about doing that but wasn't sure if it was the right thing to do...shouldn't I multiply by Time.deltaTime ins$$anonymous$$d, even in Fixedupdate?
I tried it, and even with a really high multiplier, the forces applied were super weak using Force$$anonymous$$ode.Inpulse (which I have been using all this time), but with Force$$anonymous$$ode.VelocityChange, the forces applied were strong enough again - same high multiplier - which is why I said that I am not sure this is the right way to do it, since it seams that all the other Force$$anonymous$$ode don't work correctly when multiplying by fixedDeltaTime or deltaTime...maybe I am doing something wrong?
Well the reason you are seeing what you are seeing is because one instantly changes the velocity ignoring the mass of the object (meaning the property "mass" of your rigid body) while the other takes it into account.
So, if your object's mass is large then it would make sense that Force$$anonymous$$ode.Impulse would be weaker.
Force$$anonymous$$ode.VelocityChange: http://docs.unity3d.com/Documentation/ScriptReference/Force$$anonymous$$ode.VelocityChange.html
Force$$anonymous$$ode.Impulse: http://docs.unity3d.com/Documentation/ScriptReference/Force$$anonymous$$ode.Impulse.html
Ah thx, I did not know about this :) But, when I was doing my testing, I raised the force being applied to my rigidbody (whit Impulse) to a ridiculously high number like 5000000, and it barely made a difference. When I don't multiply that by deltaTime or fixedDelatTime in FixedUpdate, then the forces being applied work as they should (I need like 10 times more forces when using Impulse then I do when using VelocityChange).
I'll try again and see if maybe I was doing something wrong...
So yeah I was doing something wrong, works as expected now, thanks guys!
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Physics: Is it possible to count the number of colliders hit with OverlapSphere? 1 Answer
Make car CenterOfMass change dynamically 1 Answer
If statment to check if player is within collider 1 Answer
Parenting player to car on click. 1 Answer