This project has moved and is read-only. For the latest updates, please go here.

[bug] frame rate and Body.ApplyForce

Topics: Developer Forum, Project Management Forum, User Forum
Jan 21, 2012 at 5:52 PM
Edited Jan 21, 2012 at 5:52 PM

Hi my name name is Fabio and I make game cross plattform between xbox and windows phone.

If I have a frame rate free and use body.ApplyForce it's not constant speed.

I just write in this forum for this problem and I resolve with this solution:

Body.ApplyForce(Direction * 2000 * (float)gameTime.ElapsedGameTime.TotalSeconds);

On xbox work fine, I set a free timestep with I have a frame rate between 60 and 140 fps.

On windowsPhone don't work fine, if I set free time step 
I have a frame rate between 25 and 50 fps. 
when frame rate works around 30fps the body move it's very slow.

this is a bug?
Jan 22, 2012 at 12:09 AM

I think this is part of a more general problem - variable step rate.

For reference:

Jan 22, 2012 at 10:22 AM

I don't think is "general problem - variable step rate" bacause between 45 and 200 fps all work fine but under 45 fps the bodies are very slow, the bullet.


if work fine with 50fps or 200fps why dont work fine with 30fps?

Jan 22, 2012 at 12:59 PM

Well the only thing that comes to my mind assuming it's not an issue of CPU power (it's slow because actually the effective frame rate drops) is that perhaps the solver becomes unstable.

BTW the forces you are applying are huge as per your example - if Direction is normalized and you play for 20 min then your force will be 1.2 mega Newtons. As it is suggested by Box2D you should keep everything more similar to the real world (e.g. bodies between 0.1 and 10 m in size and hence densities, forces etc.). I had a test where I was applying forces of about 10-20 kN and it was very weird. Once I scaled it down to the 10-100N it was much more stable.

Jan 22, 2012 at 1:18 PM

I apply this force because it's slow but don't change

Jan 22, 2012 at 7:43 PM

I found the issue! but not the solution :(

Body.LinearVelocity = Direction * 200;

with this code if fix my game at 30fps my bullet speed at 60

if fix at 60fps my bullet speed at 117