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 recently implemented an authoritative server (node.js with socket.io) for a multiplayer pong game.

I've looked at client side prediction and fixing timesteps and starting to grasp the notion of simulated identical physics across server and clients.

However, I still can't quite figure out the approach to how to detect when the paddle truly hits the ball. The paddles can be controlled by touch or mouse movement which can be an almost instantaneous teleport to the location of the ball.

How can I determine if the paddle was in the right place at the right time taking into account the round trip time?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

With an authoritative server, there is no way of being 100% fair without exposing the player to latency. There is always the possibility that the player made a sudden move that didn't reach the server before the ball passes the paddle, resulting in the player failing even when he should have hit it. But if the ping is low enough and 100% fariness is not required, you could be fine.

If 100% fairness is required and no latency is allowed, trusting the clients is the only option. This should be pretty straight forward. When the ball hits the player's paddle on client A, it tells about it to the others. When the ball hits the player B's paddle, client B again tells the others.

If the connection is very good, 100% fairness is required and the server has to be authoritative, it is still possible to make it using the lockstep protocol. This will introduce some latency but it might be ok with a proper connection. This was actually used as the first networking solution for Doom. In a nutshell, the game is divided into small, say 10ms, steps. On each step the client sends to the server any new player input instead of processing the input itself. At the end of the next step the server sends all received inputs back to the clients. On step 3, both clients process the inputs given on step 1 and so the games are exactly the same. If the server or the client hasn't received an input by the step it should have it, it locks until it's received. Hence the name lockstep I guess. A longer explanation can be found for example here and here.

share|improve this answer
    
Thanks for this. 100% fairness is required but pings may vary greatly. Do you think matching people up who have similar pings is a wise idea? Then the server can read historical data and 'referee' the match in the past. –  dolyth Mar 1 '13 at 23:38
add comment

I also tried to implement a real-time multiplayer pong using websockets and nodejs, there is a living instance here: http://www.pongoholic.com/

I went for a trust-the-client solution (exactly the second solution suggested by JohannesA). This ensures a 100% fairness, however, even the 60ms round trip time provided by websocket introduces latency in the game. I tried several solutions, such as dead reckoning, but none was 100% accurate.

Finally I had no time to test is, but I suppose that a good solution would be to use a mix of:

  • dead reckoning user B sends to user A its position, velocity and a timestamp so that user A infer the current paddle position using a linear equation of motion:
    current_paddle_position = previous_paddle_position + paddle_velocity * delta_t
    This will help approaching the paddle from the ball but can introduce oscillations
  • artificial inteligence (the AI term is really over the top here, but I did not know how to name it) Add an additional accelereration assuming that the player is trying to catch the ball with its paddle. This might reduce the oscillations while providing a good approximation of what the user is intenting. Finally:
    current_paddle_position = previous_paddle_position + paddle_velocity * delta_t + ai_acceleration * some_tuning_factor

At first I thought a pong-like would be the easiest game to try real-time multiplayer stuff, however it appeared that even the smallest latency is a lot for this type of game...

share|improve this answer
    
Hey why is this downvoted? –  Flolagale Mar 6 '13 at 11:05
add comment

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.