# How to extrapolate in Box2D?

This topic is 1020 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
19
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013601
×