• Advertisement
Sign in to follow this  

How to extrapolate in Box2D?

This topic is 782 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!

I have a position, velocity vectors and a ping value. I step Box2D world like this, just in case:

accum += delta;
while(accum >= delta)
{
    world.step(Constants.STEP, 6, 2);
    accum -= Constants.STEP;
}

I think that velocity is not constant and changes after every step. So how could I find object's position after a specific time, e.g. 50ms? I don't want to create a separate world and step it.

Share this post


Link to post
Share on other sites
Advertisement

Hi!

I have a position, velocity vectors and a ping value. I step Box2D world like this, just in case:

accum += delta;
while(accum >= delta)
{
    world.step(Constants.STEP, 6, 2);
    accum -= Constants.STEP;
}

I think that velocity is not constant and changes after every step. So how could I find object's position after a specific time, e.g. 50ms? I don't want to create a separate world and step it.

 

Loop should be 

while(accum >= Constants.STEP)

You could calculcate positions for rendering to be box2dPosition + box2dVelocity * extrapolateTime. But this cause ugly tunneling and glitches when velocity suddenly change.

Share this post


Link to post
Share on other sites

extrapolateTime is in seconds, right? Velocity isn't constant, it should be always decreasing, so why do we consider it as constant then? Also, how about gravity? I have a gravityScale variable to consider.

This extrapolation formula seems to be for non-physics world.

Edited by Gintas Z.

Share this post


Link to post
Share on other sites
You can use this formular under the assumption that gravity is constant, just use your gravity vector as acceleration:

displacement = velocity * time + 0.5 * acceleration * time*time

Share this post


Link to post
Share on other sites
No, mass matters if you want to calculate the force gravity causes (force = gravity * mass),
but resulting acceleration equals for bodies of different masses.

(I remember the school experiment, where a feather in vacuum falls down as fast as a iron ball)

Share this post


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

  • Advertisement