I do not know the ideal solution, and I have the feeling that it is not. Even if you could accurately predict the future position of the vehicle, you could not predict how the user will control the controls. Thus, the problem boils down to minimizing the negative effects of client / server delays. With this in mind, I would like to approach this from the perspective of the principle of least surprise (reworded from Wikipedia):
In user interface design, the principle of least surprise (or surprise) states that when two elements of an interface conflict or are ambiguous, the behavior should be the one that will least surprise a person when a conflict occurs.
In your example, each user sees two cars. Their own and the other player. The user expects that their own car will behave exactly the way they control it, so we cannot play with this aspect of modeling. However, the user cannot know exactly how the other user controls his car, and I would use this ambiguity to hide the lag from the user.
Here is the basic idea:
- The server must decide on an impending collision. The collision detection algorithm should not be 100% perfect, it should be close enough to avoid obvious inconsistencies.
- As soon as the server determines that the two vehicles will collide, it sends each of the two users a message stating that a collision is imminent.
- On client A, the position of vehicle B is adjusted (realistically) to ensure that a collision occurs.
- On client B, the position of vehicle A is adjusted (realistic) to ensure that a collision occurs.
- During a collision, the position of each vehicle can be adjusted as necessary so that the end result matches the rest of the game. This piece is exactly what MedicineMan suggested in his answer .
Thus, each user is still in full control of their own car. When a collision occurs, it will not be unexpected. Each user will see the movement of another vehicle towards them, and they will still have a sense of simulation in real time. It's nice that this method responds well to low latency conditions. If both clients have low latency connections to the server, the size of the adjustment will be small. The end result, of course, will worsen as the gap increases, but this is inevitable. If someone plays a fast-paced game for connecting with a delay of a few seconds, they simply will not get the full experience.
e.James May 07, '09 at 19:10 2009-05-07 19:10
source share