OK so I got my game up and running, but my physics are way off. The gravity is set to (0, -10) and the time step is 1/60. What could be wrong?
Physics problem
General DiscussionNo idea, we'll need more info about what's wrong.
Based on what you've said, the only thing I can think of is to make sure that you set your physics step as 1.0f/60.0f - if you just wrote 1/60, depending what language you're in that may be calculated using integer math, in which case it evaluates to 0.
Based on what you've said, the only thing I can think of is to make sure that you set your physics step as 1.0f/60.0f - if you just wrote 1/60, depending what language you're in that may be calculated using integer math, in which case it evaluates to 0.
The first thing I ran into was scale. Units are basically equivalent to meters. So if the scale of your objects is vastly larger or smaller, then the simulation may not be what you desire.
Thanks for the replies. Yes, the step is 1.0f / 60.0f, but thats for trying.
That was one thing I thought about, scale, but I don't know how it would affect it. So... how would it affect it? I mean how could the scale change to be wrong?
That's my display function, see anything wrong?
That was one thing I thought about, scale, but I don't know how it would affect it. So... how would it affect it? I mean how could the scale change to be wrong?
Code:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float32 timeStep = 1.0f / 60.0f;
int32 vIterations = 10;
int32 pIterations = 8;
world->Step(timeStep, vIterations, pIterations);
glutSwapBuffers();
float32 timeStep = 1.0f / 60.0f;
int32 vIterations = 10;
int32 pIterations = 8;
world->Step(timeStep, vIterations, pIterations);
glutSwapBuffers();
That's my display function, see anything wrong?
Nothing wrong there that I can see.
It's still unclear what type of problem you're having, even roughly speaking - are things moving, but wrong, or are you seeing nothing at all?
It's still unclear what type of problem you're having, even roughly speaking - are things moving, but wrong, or are you seeing nothing at all?
I'm sorry I didn't really describe my problem. I belive it's the gravity because if I throw a block up with the mouse it goes up for a little, that comes rushing down. So yes, the objects move, just come down to fast. I'm not an expert with box2d, but when I changed the timestep to 1/240, it worked a little better. When I throw the blocks up at this timestep, they go wayyyyy up and never come back :p.
I hope this helps you understand my problem. I would post my program, but I'm on my touch right now.
Thanks,
Kcaz
I hope this helps you understand my problem. I would post my program, but I'm on my touch right now.
Thanks,
Kcaz
It sounds like your loop is running too fast. It needs to be close to 1/60th of a second, since that is what you're telling Box2D it is running at.
Oh ok like the glut loop... How do I change that speed?
Assuming this is C++ under Windows, use something like GetTickCount() to get a millisecond timer, then each frame determine the duration of the last frame (current tick minus last tick), and Sleep however many milliseconds you need to make the frame last 1/60th of a second.
Dan
Dan
Ok well I added a timer and initialized it in GLUT. Now it runs to slow. My timer is:
This is inside the function called timer, I have the last line also in the main function
framePeriod is 16 milliseconds, or 1/60 seconds. Why is it running too slowley?
Code:
glutSetWindow(mainWindow);
glutPostRedisplay();
glutTimerFunc(framePeriod, timer, 0);
glutPostRedisplay();
glutTimerFunc(framePeriod, timer, 0);
This is inside the function called timer, I have the last line also in the main function
framePeriod is 16 milliseconds, or 1/60 seconds. Why is it running too slowley?
Original thread: https://box2d.org/forum/viewtopic.php?t=2889