Search Unity

Resolved Overlayed camera with items on the ground, how would I go about doing this?

Discussion in 'Scripting' started by IncrediblyWalrus, Dec 4, 2022.

  1. IncrediblyWalrus

    IncrediblyWalrus

    Joined:
    Jul 22, 2019
    Posts:
    46
    Hi there,

    I'm attempting to use an overlayed camera for my items and my first person arms, all is well, it works amazingly. However, my situation becomes an issue when I have the same items I use for my first person view also on the ground, for me to pick up.

    My overlay camera picks this up, as well as the main camera that I use to view the world in front of me. So it's overlapping. I've countered this by making my overlay camera have a maximum far view value of 1.

    That's fine, so now the overlay camera doesn't show the item from afar if it is on the ground, my first person camera will only show the item(s) only if the item is picked up. However, the main camera also now shows the same item on pickup. Here's a video clip to show you what I mean:



    The darker flashlight is the main camera showing the item, the lighter flashlight is my First Person Model camera, which is the only one I want showing it.

    My question is: How would I go about hiding the Flashlight from the main cameras perspective? I could obviously use culling mask, but then that would hide the items on the ground, which I don't want. Using my overlay camera for the items on the ground also wouldn't work, as I'd be able to see them through other objects in the scene due to be being an overlay camera.

    I could also alter the near value on the main camera but that wouldn't work as good, as that basically creates a situation on a reason why I wanted an overlay camera in the first place; so that the player doesn't see through walls.

    I'm confused on how I'd go about fixing this situation I'm in, I can try to explain my issue more if you're confused on what I'm waffling on about. It's all a little weird to explain, but I appreciate anybody that decides to help me out here.

    Thanks.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    1. Change the picked up object's layer when you pick it up
    2. Use a completely different object for the "held" version of the object vs the "on the ground" version. This is perhaps the more common approach.
     
  3. IncrediblyWalrus

    IncrediblyWalrus

    Joined:
    Jul 22, 2019
    Posts:
    46
    I have thought about doing the first one, but that could mean a lot of different layers happening, due to the fact there'd be multiple items on the ground. And I don't really want the player to miss an item just because they're holding something. Also if there's another flashlight hiding around, and a player has one picked up, but I hide the flashlight layer, they won't see an extra one.

    I might do the second option, unless someone chimes in here with another idea that I might've missed. The second option just might be a bit difficult, due to the fact I'm using Photon, and my way of going about it is using Photon's transform view component where it syncs for other players, so that's why I'm picking them up from the ground, and the player then easily has that synced without me doing much.
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    I don't understand the logic here. All you have to do is change the layer of the specific flashlight you picked up. It shouldn't affect any other objects whatsoever, including other flashlights. Also doesn't make sense to me that there's a "flashlight layer" at all.

    This is what I'm imagining, two layers:
    - ObjectOnGround layer (this is the layer objects on the ground have)
    - InHands layer (this is the layer of objects in your hands, and your hands themselves) The secondary camera only renders this layer)

    When you pick up an item you change its layer to the InHands layer. When you drop it you change it back.
     
    Last edited: Dec 4, 2022
  5. IncrediblyWalrus

    IncrediblyWalrus

    Joined:
    Jul 22, 2019
    Posts:
    46
    Okay yeah, I honestly have no idea why I never thought about changing the layer for the individual items instead, rather than the culling mask situation.

    I've tried it out really quickly and it worked well on my end, so I appreciate that.
     
    PraetorBlue likes this.