# How to extrapolate in Box2D?

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

## 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 on other sites

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 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 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 on other sites

I will check it. Also, should object's mass be a factor?

##### 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 on other sites

I tested it, seems to work fine, thanks :)

1. 1
2. 2
Rutin
22
3. 3
JoeJ
20
4. 4
5. 5

• 27
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631735
• Total Posts
3001940
×