Search Unity

Third Party Unity Multiplayer Bullet Shooting - Photon ?

Discussion in 'Multiplayer' started by brudi, Dec 4, 2016.

  1. brudi

    brudi

    Joined:
    May 5, 2016
    Posts:
    2
    Hey there, i have a basic game with photon integrated.

    Basically it is about shooting bullets, but not via "RayCast", it is more about shooting bullets at normal speed
    (so you still can see bullets moving on screen).
    So what i did:

    Player A shoots.
    - Bullet is instantiated locally
    - RPC is send to all clients, including the instantiation position of the bullet
    Player B receives RPC
    - Bullet is also instantiated locally with given position from RPC

    So far so good.

    When Player B gets hit by this bullet:
    - first the bullet-gameobject gets destroyed locally
    - secondly Player B sends RPC to all clients that he was hit and that they should delete this bullet locally too.

    So collision detection with bullet is always done on the client, who gets hit
    and next he informs all other clients about this event.

    So... it works fine :)
    BUT:

    Before Player A gets notified about his successfull shot, in his client the bullet already collided with Player B and moved on and was destroyed far to late...

    So anyone knows a proven strategy to solve this problem?
    Should i change my strategy or move to an other solution.. ?

    Thanks and Greetings!
     
  2. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    In my FPS project I did like this: I have 2 types of shooting: local and global. The local one is for your own view and has the damage logic included + FX. The global one is used for the bullet FX only to "fake" the local shoot. So what you do with the local one is detect collision, play FX and send the damage to THE collided photonplayer (not all targets), since his health value should be state sync it will be automatically synced with all others "OnPhotonSerializeView". The global one fires with RPC but only PhotonTargets.Others (the global bullet is only for your networking clients you dont need to execute it on your client), so it collides, plays bullet FX and destories. That's how most first peson shooters doing it, since I don't kow which type of game you have, it may be not relevant.
     
    eclipse130300 likes this.