Concurrent pick up

Hello there. As you already figured out I want to implement concurrent picking up in my game (with 4 players max).
I have already checked the demo, but I don't really understand why it is concurrent, and how it prevents the situation when two players trying to pick up the same object.

As far as I can see, in the demo we doing the next.

When a player picks up an object, we check, whether it's our player or not, and if it is, then we send an RPC to all players, via server. When the RPC is called via server, we check if this call of RPC was performed by us, and if it is, then we add score.

But what will happen if on the other client another player picks up the same object at the same time? Then it will call the same RPC twice, but for different players, and when it come via server then two players get a score, right?

Please, tell me if I'm right or not, and if I am, how to deal with the problem.

Comments

  • I was wondering about the same thing, but didn't see this post till now:

    My thread: http://forum.photonengine.com/discussion/9313/stopping-multiple-players-collecting-same-powerup#latest

    It does offer some of my own thoughts on how to deal with this...
  • @ChazAshley
    I've taken a closer look at the demo scene, I believe this does prevent 2 players concurrently pickig up the same pickup.

    Each client executes its own RPCs and the other players. so the first PunPickup RPC to get processed from the servers (in-order) RPC list would disable the pickup game object. The pickup game object is checked for whether it is active or not in PickUpItem::PunPickup() and if it's not, it bails early. This is the cruciial piece of logic that prevents multiple players gettign the same pickup.

    From my understanding, it will look like this, assume that latency is zero and the frames are the frame number on the sevrer.

    * Server Frame 0: Player 1 picks up Item 0 and sends PunPickup RPC
    * Server Frame 0: Player 2 picks up Item 0 and sends PunPickup RPC

    * Server Frame 1: Server receives both PunPickup RPCs at the same time and arbitrarily orders them in a list: Player 1 followed by Player 2.

    * Server Frame 2: Player 1 receives the in-order RPCs from the server, it processes the RPC from itself first (as this is how the server ordered it) and successfully gets the pickup. It then process the Player 2 RPC, but as the pickup GameObject is now disabled, it bails early.
    * Server Frame 2: Player 2 receives the in-order RPCs from the server, it processes Player 1's first (as this is how the server ordered it) and Player 1 gets the pickup. It then processes it's own RPC, but as the pickup GameObject is now disabled, it bails early, narrowly missing out on getting the pickup for itself.
  • Don't send the rpc "via server" so it executed locally immediately... Then do an ownership request callback and course correct for the edge case (just disappear it for 2nd player in line or do a clever animation or something).