• Advertisement
Sign in to follow this  

Box2D is acting weird

This topic is 2291 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi im a new member of Gamedev, and im having a problem with Box2D and SFML.

I recently(2 Weeks ago) began learning Box2D and when i start my test program it simulates too quickly I think its because of the b2World Step function getting the wrong TimeStep.

My Framework is set up to use the class WindowManager for everthing related to the RenderWindow. I made a function inside it called GetFrameRate and it returns the framerate.

This is the code i use for the handle function in my PhysicsHandler class

void PhysicsHandler::Handle(float FrameRate)
{
if(FrameRate < 0.1)
return;

float TimeStep = 1.0f/FrameRate;
const int VelocityIterations = 15;
const int PositionIterations = 12;

PhysicsWorld->Step(TimeStep,VelocityIterations, PositionIterations);
}

So it takes 1 divided by the FrameRate returned from GetFrameRate()

Im really stuck.

Share this post


Link to post
Share on other sites
Advertisement
From Box2D manual : [url="http://www.box2d.org/manual.html#_Toc258082976"]http://www.box2d.org/manual.html#_Toc258082976[/url]

"[font=Calibri, sans-serif][size=2]We also don't like the time step to change much. A variable time step produces variable results, which makes it difficult to debug. So don't tie the time step to your frame rate (unless you really, really have to). "[/size][/font]

Share this post


Link to post
Share on other sites
[quote name='Gamer Gamester' timestamp='1318307524' post='4871327']
See the article "Fix Your Timestep" by Glen Fiedler.
[/quote]

[url=http://gafferongames.com/game-physics/fix-your-timestep/]Link[/url].

Share this post


Link to post
Share on other sites
Maybe you fell for the other common trap: Don't give object sizes in pixel, give them in natural values.

It's a comment in the Box2d docs somewhere deeper, while it should be in bold red, blinking on top.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement