How to prevent race condition bugs due to ping ?

Started by
1 comment, last by hplus0603 4 years, 8 months ago

Hi

 

I have a situation where players can use an item in a game where they walk up to an item and interact with it. But only one person can at a time. 

How do you prevent the situation where the local user interacts and a remote player interacts at the same time and decide who should use it ? It seems like there is a potential window where both could end up using it before the system is aware that one of them is already using it. 

My other worry is if i have players who go to use a component, request the host if they can use it based on if its available for use, then everything will feel laggy in terms of response times when using things. Is there no real clean way to solve that other than accept a slower responsive time by asking the host if its usable ? 

Advertisement

Make the "time to use" the item longer than the maximum round-trip-time you're prepared to accept. (The canonical example is walking over a health pack in a game like Quake.)

Thus, when the player walks up to the item and uses it, you can start playing the "use item" sound, but don't apply the effects until enough time has passed to break the tie.

If two players walk up and use the item, one of them will "win" (be first,) both of them will hear the "start using" sound, and the effects will accrue to whomever won the tie.

 

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement