# How to predict future position of an object(bullet sync)?

There is a multiplayer game and server sends to all clients a message when a shot happens, containing bullet position, bullet velocity and timestamp. By having timestamp, we can calculate the lag, let's say it's 100ms.

My game uses Box2D. How can I predict the real and current bullet position by having such data? I guess velocity might also change a little bit too.

## 1 Answer

current_position = starting_position + ((lag_delay + time_elapsed ) * velocity)

Where "time elapsed" is how long we've known about the bullet existence. Ostensibly this doesn't need to be stored, as when the bullet is created client-side, it is 0, and afterwards we update its position every frame update.

The lag delay is merely just an extra bit of deltaTime applied when the bullet is first spawned.

• I guess this only works for linear, straight line bullets. What about ones that are affected by gravity? – Gintas_ Dec 30 '15 at 15:42
• Calculate the gravity for the lag_time as well. Seriously, all the lag_time is is a once-off "do this much movement as the bullet spawns" calculation. – Draco18s Dec 30 '15 at 15:43
• can you provide an example please? – Gintas_ Dec 30 '15 at 15:45
• pastebin.com/vuCsZc3B – Draco18s Dec 30 '15 at 16:04