0
\$\begingroup\$

In my game, my own character is extrapolated with client side prediction for smooth input response and all the other objects are interpolated. So Let's say I was at (20, 10) according to server and a bullet hits me at that position. But my client displayed rendered myself at predicted position (23, 10), which leads to a discrepancy - I got hit by the bullet even though it looked like I wasn't hit. How can I deal with this problem?

\$\endgroup\$
2
  • \$\begingroup\$ Move your character when bullet hits you? No? \$\endgroup\$
    – Ocelot
    Mar 8, 2016 at 0:44
  • \$\begingroup\$ What exactly is the problem? Do you mean the bullet travelled through the (20, 10) point, and thus hit the client, but to the client they are at a different position and thus aren't in the path of the bullet? Sorry if this sounds like a dumb question, but there are many types of network discrepancies, just want to be clear what kind you're worried about. \$\endgroup\$ Mar 8, 2016 at 9:51

2 Answers 2

2
\$\begingroup\$

It boils down to a choice: do you want a sniper that aimed perfectly to miss because the target actually moved? On the sniper's screen he got the shot.

The alternative is better: creating the possibility that you will get shot slightly after moving behind cover.

All FPS games have some form of this problem. Typically, shooter wins (because his aim was right for him), dodger loses (even though he swears he got shot after moving behind cover).

If the server "believes" the shooter, then it needs to be very careful, it needs to make sure that it was actually possible for that player to have gotten the shot. The problem exists for the victim as well, you don't want hacks to make you impossible to hit.

Generally, the server keeps track of the position and movement of a player, and can check whether it is feasible for the player to have gotten that shot within the last several game ticks.

\$\endgroup\$
1
\$\begingroup\$

For networking issues, you generally need to disguise the lag as much as possible. How you do this depends quite a bit on the type of game you're making. The situation where the lag occurs also should affect your approach.

If you had asked about shooting a bullet, the answer would be easy: use a brief firing animation on the client (but not on the server), so that the client's animation delay balances out with the networking delay, thus eliminating the appearance of lag. Getting hit by a bullet is a harder scenario though. Nonetheless, there is a solution: you not only need to predict the character's movement, you need to predict bullet movement as well (at least for bullets near the character). If you're predicting where both the character and the bullet will be 100 milliseconds after where they actually are on the server, they'll be in sync. This wouldn't work if bullets move at a very fast speed, such as if you're making a realistic FPS game, because the bullet speed would be even faster than the ping delay. If bullets move slowly enough, that's all the solution you'll need. If they move lightning fast, try predicting bullet movement before the bullet is even fired. That way, there will be enough delay to keep the character and the bullet in sync.

It isn't a perfect science, and "hiding the lag" is highly situational. Don't be afraid to alter gameplay mechanics a bit in order to make the networking work properly, because a game that feels out of sync just isn't fun to play.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .