Simulating a single Shape/Body for a few steps...

Official forum for the Chipmunk2D Physics Library.

Simulating a single Shape/Body for a few steps...

Postby Beernutts » Tue May 24, 2011 2:35 pm

I am using Chipmunk 5.3.4, and I'm coding up an action multiplayer game.

My problem is, when I send an update from one client that he's fired a bullet, there's the distinct possibility that packet will be lost, possibly multple times (using UDP). So, if the client didn't receive an Ack for that packet, he'll send it again (with more state changes as well, if needed).

What I want to know is, once the server properly receives the packet, and it's given a time the bullet was fire (as well as location and velocity), how can I simulate that bullet to locate it at the position it should be based on when the bullet was fired, but not simulate the whole space?

I suppose I could calculate the position myself based on the Location, Velocity, and time elapsed, but that might not be good if there's an object it may have collided with.

Thanks for the help.
Beernutts
 
Posts: 10
Joined: Fri May 06, 2011 9:12 pm

Re: Simulating a single Shape/Body for a few steps...

Postby slembcke » Tue May 24, 2011 3:54 pm

Quite simply, you can't. Chipmunk doesn't remember where objects have been, so you wouldn't get reliable results anyway. To do what you are asking for, you'd have to backtrack all of the objects in the space and re-run them.

If you are okay with missed dynamic collisions and only really care about checking against static geometry, you can make a copy of your static shapes and simulate the single object in that space first. Just keep in mind that you cannot share bodies/shapes/joints between spaces. You can move them back and forth as long as they aren't in both at any given time however.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Simulating a single Shape/Body for a few steps...

Postby Beernutts » Tue May 24, 2011 4:27 pm

Bummer. I figured what I was trying to do would be near to impossible to do properly.

OK, I'll try and work something out.

Thanks!
Beernutts
 
Posts: 10
Joined: Fri May 06, 2011 9:12 pm

Re: Simulating a single Shape/Body for a few steps...

Postby slembcke » Tue May 24, 2011 5:26 pm

Well, the problem isn't specific to Chipmunk either. In a lot of networked physics games, it's pretty apparent that what they are doing is assuming that the local simulation is correct until it receives a position/velocity update from the server. When that happens, it just uses the given position and velocity to figure out where it should be now compared to when the packet was sent. It's not perfect, but it does work pretty well. You just can't have gameplay code running on the local machine that is dependent on the simulation to be completely correct.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Simulating a single Shape/Body for a few steps...

Postby Beoran » Sat May 28, 2011 4:23 pm

There are two ways to handle this properly.

The first one is to let the server run the simulation and make the clients as dumb as possible. Let the client only send input events, whilst whilst the server tells the client what to draw where.

If that's too heavy to be practical, then let the all clients run the simulation simultaneously, and let the server merely forward the input of each client to all other clients the same game level/zone/area, so they can use it to simulate the other client's motions.

Both solutions make cheating difficult because in the first case, the client does not control the simulation on the server, whilst in the second case, the client does not control the simulation /in other clients/. The latter case allows local cheating in one's own game, but the cheat cannot propagate if the server and the other clients validate the input.

Hope these suggestions gave you some ideas.

B.
Beoran
 
Posts: 19
Joined: Sat Apr 12, 2008 2:02 pm

Re: Simulating a single Shape/Body for a few steps...

Postby Beernutts » Tue May 31, 2011 3:50 pm

Beoran wrote:There are two ways to handle this properly.

The first one is to let the server run the simulation and make the clients as dumb as possible. Let the client only send input events, whilst whilst the server tells the client what to draw where.


This would result in the same behavior the original "Net Quake" experienced, ie, the player wouldn't move/shoot, until the command had gotten to the server, and the client received a response. This creates noticeable lag in the time of pressing a button, and seeing the results. I do not want this.

If that's too heavy to be practical, then let the all clients run the simulation simultaneously, and let the server merely forward the input of each client to all other clients the same game level/zone/area, so they can use it to simulate the other client's motions.


This would still exhibit the problem I was writing about. When the client pressing the "fire" button, it generates the bullet then and there, and it begins to move (assuming it's not instant). The "bullet fired" notification (via input), however, may take multiple re-sends to get to the other players, along with built in latency, and, by the time it does get there, the bullet may have traveled a non-negligible distant on the original players client.

My solution is, when a remote client receives the bullet shoot notification, it will simulate the distance traveled by the bullet locally (before giving it to the ChipmunkPhysics "space"), and assume that (hopefully very short) distance wouldn't affect the possible items it could have interacted with.

Thanks for the response though, I always like suggestions.
Beernutts
 
Posts: 10
Joined: Fri May 06, 2011 9:12 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 0 guests

cron