1
\$\begingroup\$

Trying to decide the best course of action to implement the in view and out of view of players in a server/client 2D game. Below is some highlights of the system:

  • Map sliced into squares. Each square contains players and objects.
  • Check 2 square radius around player for other players/objects. Send full info states of these players/objects when in range.
  • Save that X player knows about each player/objects full data, only send position states thereafter.
  • Client Side: If player moves outside a set range, set it invisible. If player comes back in range, set visible.

Now my problem is the following scenario:

  • Player 1 sees Player 2
  • Player 2 walks out of set range. Player 1's client hides that player.
  • Player 2 continues on and is far far away.
  • Player 1 walks towards where Player 2 went invisible.
  • Player 1's client sees the last position we got from Player 2 and unhides it.

So how would I verify if the last position Player 1's client got of Player 2 is their real position? The following scenarios I've thought about:

  • Hide characters indefinitely if they are out of view and only show again if we get movement state. This doesn't work as there are many stationary objects and players may not always be moving.

  • On client set a flag on characters as "out of view" as they leave view. Don't show again unless the server says something is there. The server would have to keep track of that and resend proper information once a character gets back in view. It seems this is the only possible way to make it work, that the server would have to control this in view and out of view feature. Of course this seems like a ton of overhead for the server to do especially if not everything changes.

What is the proper way to handle this situation? I'd appreciate any feedback. Thanks.

\$\endgroup\$
  • \$\begingroup\$ This paradox and set of complications is why "out of view" state isn't cached on clients and that "ton of overhead" is handled by the server. It's not as much overhead as you are assuming. \$\endgroup\$ – Patrick Hughes Jan 8 '16 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.