Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Client Camera Render

Discussion in 'Scripting' started by CGArtistLeo, Apr 15, 2014.

  1. CGArtistLeo

    CGArtistLeo

    Joined:
    Feb 13, 2014
    Posts:
    5
    Hello! I'm not sure if this is the correct place to put this thread, but I assume it would deal more with scripting than it would anything else (I assume).

    I'm building a driving game and I'm trying to figure out how the mechanics behind client views work. I am trying to render a car dashboard for the only the player, while rendering the full car model (including functionality) in the others.

    I am currently using 1 camera that instantiates when a player spawns. Each player prefab renders with a full car model, and an interior.

    With my understanding, cameras have layers you can use, but it doesn't quite add up for me.

    Render options are WORLD, VEHICLES, and INTERIOR.
    Camera only renders INTERIOR, and WORLD because the player should only see the INTERIOR and not its own VEHICLES.
    But that also means that it won't render the other VEHICLES in the scene.
    But if I enable render for VEHICLES also, then the player VEHICLES will be visible to the player.

    I was told it would have something to do with disabling and enabling cameras in script, but I'm not really sure about the logic behind this. Thanks ahead of time for the help.

    Thanks!
     
  2. CGArtistLeo

    CGArtistLeo

    Joined:
    Feb 13, 2014
    Posts:
    5
    bump.

    Does anybody have any kind of idea? At least something to start me off? Thank you!
     
  3. wondyr

    wondyr

    Joined:
    Nov 30, 2013
    Posts:
    36
    My best guess would be try thinking of it as a FPS even though it's a racing game. Interior mode is 1st person and World mode would be 3rd person.
     
  4. CGArtistLeo

    CGArtistLeo

    Joined:
    Feb 13, 2014
    Posts:
    5
    That's actually what I was thinking of and also looking up. Problem is, the issue would also be apparent in an FPS shooter, swap INTERIOR and VEHICLES with FIRSTPERSONMESH and THIRDPERSONMESH respectively.

    There have been answers in those threads about FPS shooters, but they don't make a lot of sense to me when I pose the scenario above.
     
  5. CGArtistLeo

    CGArtistLeo

    Joined:
    Feb 13, 2014
    Posts:
    5
    So after months of putting this off, I came back and tried to actually figure this out. Turns out the answer wasn't even in the layers or tags at all! This is how I did it:

    Create a the interior and exterior meshes and put them in the correct position. Start them off as inactive. Then create a script (or add to an existing script). First create 2 public variables that will hold the interior and exterior mesh.

    Code (JavaScript):
    1. var interiorMesh : GameObject;
    2. var exteriorMesh : GameObject;
    Then add this code in the Awake function.

    Code (JavaScript):
    1. function Awake ()
    2. {
    3.      if (NetworkView.isMine)
    4.      {
    5.           interiorMesh.active = true;
    6.      }else{
    7.           exteriorMesh.active = true;
    8.      }
    9. }
    Then go into the Unity Inspector and drag the interior and exterior mesh to their appropriate slots.

    And that's it! Basically, the code says as soon as the object is created, find if the NetworkView belongs to the current user. If it does then the interior mesh is shown, and all other players will have their exterior mesh visible because the NetworkView doesn't belong to them.

    Hope this helps someone in the future!