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

Rendering Player and Gun in Front of Other Objects?

Discussion in 'Scripting' started by TheChronicPhenix, Oct 22, 2010.

  1. TheChronicPhenix

    TheChronicPhenix

    Joined:
    Jan 14, 2010
    Posts:
    874
    So I'm making an FPS game, but I want to render the gun and player in front of everything else, so that even if the gun was sticking through and object it wouldn't matter because it wouldn't look like it. There was a topic a while back, I think it had something about using two cameras, but I can't find the topic and can't figure out how the two cameras are supposed to work together, is there a simpler solution? or can someone tell me how to do it with the two cameras? Thanks.
     
  2. ivkoni

    ivkoni

    Joined:
    Jan 26, 2009
    Posts:
    978
    the rendering order is defined by the queue tag in your shader. What you can do is take the existing shader that you use(take the code for it) built in shaders
    and only change the rendering queue to something like Overlay, or Geometry + 10...
    http://unity3d.com/support/documentation/Components/SL-SubshaderTags.html
    Then use this new shader for the gun material.

    you can also do it with 2 cameras as follows:
    Create a camera that is depth only (rather than skybox).
    Set its depth property to be higher than the depth of the main camera.
    Put your gun in a specific layer, say gunlayer).
    Change the culling mask of the main camera to ignore gunlayer.
    Change the culling mask of the second camera to render only the gunlayer
     
  3. TheChronicPhenix

    TheChronicPhenix

    Joined:
    Jan 14, 2010
    Posts:
    874
    Awesome! That worked perfectly. Thanks!
     
  4. Galactic_Muffin

    Galactic_Muffin

    Joined:
    Aug 14, 2013
    Posts:
    67
    could you please elaborate on this shader method? the duel camera solution worked for me but only within unity. it does not however work when applied to Augmented reality. basically I need just one camera to handle the render priority rather than 2 cameras to fix my problem.
     
  5. Roderyk

    Roderyk

    Joined:
    Mar 5, 2015
    Posts:
    75
    5 years post.
    That's some necro posting there.
     
  6. Goffa

    Goffa

    Joined:
    Dec 2, 2013
    Posts:
    8
    9 year old post now, saved my life, sorry for the necro..
     
  7. BlueberryCraze

    BlueberryCraze

    Joined:
    Jul 11, 2017
    Posts:
    1
    Older now, 12 years ago. Damn. Time really moves huh?
     
  8. Saydus

    Saydus

    Joined:
    Nov 6, 2019
    Posts:
    1
    I manage to do this by creating a new shader and modifying the render queue.

    Create a new shader, and open it. Inside the shader script find the "subshader" and inside it add ZTest Always, and save your shader. Create a new material and use the new shader you've created. At the bottom part of your material inspector find "renderQueue" and change this number higher than 2000. Drag the material to the object you want to render on top of others.

    That should render your objects on top of others.