Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've troubles wrapping my head around multiplayer physics and collisions on the client side, so far I interpolate the state of my network entities ( position and velocity ) of the other clients based on the snapshot data I receive, but how should I handle collisions on the client side?

If I bump into another player, should I calculate the new position of the other player immediately after I interpolated the state or should I just predict the collision response of my local player and don't set a new position / velocity of the network entity on my client?

share|improve this question
    
A couple of answers in gamedev.stackexchange.com/questions/6645/… should get you understanding this better. –  Tim Holt Jan 17 '13 at 18:24

1 Answer 1

up vote 3 down vote accepted

In general, the server should be the sole authority for calculating object positions and movement vectors. The clients should only send their intention to move to a certain destination or into a certain direction, and the server should respond with a new movement vector, when it decides to allow the client to do so.

The server should also be allowed to send movement vectors which are not a response to a client, or even directly contradict what the client is saying, like when the movement destination of the client is blocked by another object.

A client can assume that the server will allow them to perform a move and already show the player character moving even though the server didn't sent a new movement vector. This makes the network latency less apparent to the user and thus offers a more fluent game experience. But the client should be prepared to correct the position of the player character when the server decides to deny or interrupt the movement, for example because there is a collision with another object.

Example:

  1. User issues a move command
  2. Client checks if the move may be performed according to its current view of the game state, and decides that it's possible
  3. Client sends the move command to the server, and already starts to move the player character, because it assumes that the server will allow it.
  4. Server receives the move command, and decides to deny it because there is something in the way the client wasn't aware of or didn't consider to be in the way due to timing differences
  5. Server sends a rejection message to the client
  6. Client stops moving the player character and moves it back to the original position
share|improve this answer
    
ok I assume you are talking about clientside prediction and I think i understand that so far, but to be clear let me rephrase my question : Lets say another player is moving towards me, and I move towards him and we collide, should the other player stop immediatly or should he just stop when the server says so? –  coffeecup Jan 17 '13 at 12:48
    
Your client never sends collision responses to other players - only the server has authority to do that. The client is of course allowed to predict that there will be a collision and already move all participants accordingly (locally), but it has to be prepared for the server to report something different. Think of your clients to be soccer players and of the server as the referee. It's not a foul-play when a player shouts "foul" - it only is when the referee says so. So when you think there was a foul-play, you better keep playing, because the referee might decide differently. –  Philipp Jan 17 '13 at 12:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.