Jump to content
  • Advertisement
zqf

Client movement prediction in physics engines

Recommended Posts

I'm creating a networked game with a large object count and was planning to integrate in the bullet physics engine. However, I have been using server corrected client prediction to give clients smooth movement, rewinding and replaying to synchronise.

The only way I can think of doing this in a physics engine like Bullet, which as far as I can tell can only step the whole simulation at a time, is to either store the positions of every object in the whole sim for some period of time and snap hundreds/thousands of objects back, or to handle motion of objects manually, which partly defeats the purpose of using the physics engine in the first place.


How could I handle this kind of thing?

Share this post


Link to post
Share on other sites
Advertisement

You don't need to snap every object at once. You can snap only some objects, closer to the player with higher frequency, for example.

Similarly, you can know which objects are "touched" by the player entity, and thus are likely to be out of sync, and prioritize snapping those.

Finally, when you "snap," you can remember the position/orientation of objects on the client, too, so you have something like:

client position at time 120: 32, 18
server position at time 120: 28, 19
client position at time 130: 40, 5

Now, the client receives "at time 120, the position was 28,19."

What the client does is calculate a delta (28-32 = -4, 19-18 = +1) and applies that to the current state (40-4=36, 5+1=6)

This works best for position/orientation, you may want to do something more server-authoritative for velocity and spin. At least if the difference is big, it's probably better to apply the server value wholesale to velocity and spin, although if the delta is small, just applying the delta as per position would be OK.

Finally, yes, this is one of many reasons why most large shooter games don't have tons of important interactive physics in their big maps 🙂

 

Share this post


Link to post
Share on other sites
Posted (edited)

Just to add to what hplus said, it very much depends on the nature of your game.

Generally the easiest solution is to simulate the physics for anything that isn't a player on the server, and the server only, so by definition what the clients see is an accurate, but delayed version of what is on the server, and no need for rewind.

Of course this breaks down when the player interacts with these physics objects, in the same way that player-player interactions often produce glitches in multiplayer, because of the time delay.

There is also the issue of how much data needs to be sent in the packets for large numbers of objects. Glenn Fiedler has some examples of cutting down the data for this kind of thing:

https://gafferongames.com/

Totally guessing at the nature of your game, as you have not specified, but perhaps you can only try and do client side prediction for the objects that are very close to the player? But of course there will be inaccuracies when these client predicted objects interact with non predicted objects etc.

You really need to give more information on the nature of the game. What are these 100/1000 objects? Are they close to the player? Are they boxes? Fish? Particles?

Edited by lawnjelly

Share this post


Link to post
Share on other sites

Are you running the clients ahead of the server (clients rewind and replay to extrapolate game state) or server ahead of the clients (server can rewind and replay to compensate for latency, clients interpolate game state)?

Share this post


Link to post
Share on other sites
Posted (edited)

 

Sorry yeah I should have called the thread something like server->client Reconciliation rather than prediction!

To clarify the game a little, it’s a kind of arcade shooter at the moment. The objects are primarily flocks of enemies, so they aren't full on tumbling physics objects but they are bumping up and moving around each other in hordes. I was also hoping to have them interacting smoothly with some moving geometry too (plus I need a good optimised spatial partition for querying).

“Are you running the clients ahead of the server (clients rewind and replay to extrapolate game state) or server ahead of the clients (server can rewind and replay to compensate for latency, clients interpolate game state)?”

The client is behind the server by lag + small jitter buffering time. The client is executing their own ‘inflight’ inputs locally before server confirmation for responsive movement. The client is, in effect, in a slightly different timezone to the rest of the simulation. The client is running the simulation locally to fill in between sync messages as described in the gaffer on games articles

The client movement scheme I have been using so far is the kind described here:

https://www.gabrielgambetta.com/client-side-prediction-server-reconciliation.html

So my primary issue is the rewind->replay of a client's inputs when the server corrects their position specifically. I can snap back for the correction but the client is then moved forward again for all user input sent since the timestamp of the correction and this is the area I don’t understand.

Edited by zqf

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!