- Home /
Rigidbody.AddForce depending on frame rate?
I got a big problem with my multiplayer game.
The players are able to kick (pressing the mouse button) in order to apply a force to the ball (rigidbody, networkview). The ball position is being networked without problems.
But I realized that depending on the FPS of the client, the force applied to the ball is higher or lower. For clients running the build under a low FPS rate, the force applied to the rigidbody is much higher than the force applied by a client running the build under a higher FPS.
In the script the impulse is made this way: rigidbody.AddForce(destiny force Time.deltaTime, ForceMode.Impulse).
Here's the build: golonline.net/play.html
Inside the game, go to Play -> Training and create a server. Try kicking (with the left mouse button) and see the result. Then try droping down the FPS somehow and repeating the process. You'll see the kick stronger at low frame rate and strong at high frame rates.
How can I solve it?
Answer by aldonaletto · Aug 09, 2012 at 01:16 AM
You should remove Time.deltaTime: if that line of code is inside Update, LateUpdate or a coroutine, the force will be inversely proportional to the frame rate. AddForce usually is frame rate independent: ForceMode.Force applies the force during one physics cycle (20mS per default), while ForceMode.Impulse "kind of" applies the force during one second (it actually concentrates the effects of one second of continuous force in a single physics cycle)
If you remove Time.deltaTime and change the mode to ForceMode.Force, things probably will behave ok without having to alter force too much.
And consider doing it in FixedUpdate ins$$anonymous$$d of Update (or using WaitForFixedUpdate in coroutine).
Is this true? I have a button listener that, on click, applies some impulse to a rigid body. If the FPS are lower, the impulse is a looot more strong...
Your answer
Follow this Question
Related Questions
NetworkView Control 2 Answers
Multiplayer Physics Extrapolation 1 Answer
Network particle collision 1 Answer
Optimize iPad multiplayer? 1 Answer
Testing my multiplayer character offline 0 Answers