Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Photon PUN RPC creates object that seemingly needs one layer for each player in the room.

Discussion in 'Multiplayer Networking' started by ALargeTurkey, May 16, 2018.

  1. ALargeTurkey

    ALargeTurkey

    Joined:
    May 29, 2017
    Posts:
    2
    I am working on a top-down, multiplayer game (~15 players per match) that uses ray casting for shooting. I am working on an ability where a player can deploy a portable shield that will appear for a few seconds and then disappear. The player who deployed the shield is able to shoot through it, but enemies cannot (think Overwatch style shields). When a player deploys the shield, an RPC is sent out to all clients saying to deploy a shield at position P and rotation R. The shield itself is not using a photonView, each client is responsible for deploying/destroying the shield.

    Right now I am putting the shield on an "IgnoreRaycast" layer for the player who deployed the shield, and a "Shield" layer for all others. The problem I am running in to is that on enemy players devices, the shield that I deployed is put on the "Shield" layer, so my photonView player object on their device is visually hitting the shield when it shouldn't be.

    A possible solution that I have thought of is to create a separate layer for every player/team that is in each match. Given that Unity only allows us to create 24 layers for our games, and that there will be ~15 players/teams per match in my game, this doesn't seem like the correct solution.

    If anyone has solved this in their games I would love to hear how! Thanks!
     
  2. voncarp

    voncarp

    Joined:
    Jan 3, 2012
    Posts:
    141
    You should be able to check it like this if the player isn't a scene object:

    Code (CSharp):
    1.  
    2. if (photonView.isMine) {
    3.       shieldObjectInstantiated.layer = LayerMask.NameToLayer ("IgnoreRaycast");
    4. }
    5. else {
    6.       shieldObjectInstantiated.layer = LayerMask.NameToLayer ("Shield");
    7. }
     
  3. ALargeTurkey

    ALargeTurkey

    Joined:
    May 29, 2017
    Posts:
    2
    This is exactly what I'm doing right now, which results in the problem outlined in my original description. The problem is that on remote players devices, the else statement sets the layer to "Shield" for ALL photonView player objects on that players device. At that point there is one shield object in the world which is on the "Shield" layer. This means that the player's photonView game object who deployed the shield wont be able to shoot through it on remote devices. On the local players device, everything is fine, but not on remote devices.
     
  4. voncarp

    voncarp

    Joined:
    Jan 3, 2012
    Posts:
    141
    Another solution is instead of firing the Raycast on all the clients, you fire it from the player and send the results across the wire. So if you were trying to have a bullet impact you would send the hit.point, hit.normal, tag number, or whatever else from the player who fired.