Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. 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 'Connected Games' started by ALargeTurkey, May 16, 2018.

  1. ALargeTurkey

    ALargeTurkey

    Joined:
    May 29, 2017
    Posts:
    3
    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:
    149
    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:
    3
    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:
    149
    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.