Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

FPS camera in multiplayer?

Discussion in 'Scripting' started by Kovenant, Oct 1, 2017.

  1. Kovenant

    Kovenant

    Joined:
    Sep 18, 2013
    Posts:
    254
    So.. I'm trying to figure out how I can make the weapon of the local player not clipping through walls in a multiplayer game. I can't put it on a layer since that would make the camera see all remote players weapons through walls and objects.

    How do you tackle this? I've been trying all sort of stuff but it just won't work. Putting a collider on the weapon is out of the question even though it's a very simple and effective solution :)
     
  2. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    207
    "I can't put it on a layer since that would make the camera see all remote players weapons through walls and objects." I don't understand what you mean by this. Why would putting the local player's weapon on a layer change how the camera sees the remote players?
     
  3. Kovenant

    Kovenant

    Joined:
    Sep 18, 2013
    Posts:
    254
    Because they are all using the same prefab.. and putting the weapon on a layer with for example "if(isLocalPlayer)" would execute on all players since each player is local on their computer.. networking is complicated..
     
  4. Kovenant

    Kovenant

    Joined:
    Sep 18, 2013
    Posts:
    254
    You can try it yourself.. just make a simple scene with a big cube in the middle, put the local players weapon on a layer which uses a Depth Only camera.. connect with another instance of the build. They would both see the remote players weapon through walls, like a wall hack :)
     
  5. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    207
    If it's because they all use the same prefab, then just create a different prefab for the player.
     
  6. Kovenant

    Kovenant

    Joined:
    Sep 18, 2013
    Posts:
    254
    Hehe... isn't that a little bit of a overkill. That means I have to have a different prefab for every player that connects, which I don't know how many there will be... ;-)

    Anyways, I solved it.. :)
     
  7. Acid-NN-9

    Acid-NN-9

    Joined:
    Apr 29, 2015
    Posts:
    10
    Kovenat, i´m interesting how you solve this problem. I have some similar situation. Please share you experience!