x


Always render a object on top of another.

Is it possible to make a object always render on top of another even if there is another object between it and the camera. Like making the gun in a FPS always render on top even if it goes trough a wall.

Im preferably looking for a way to do this with the standard version of unity, and not use any pro-only features.

more ▼

asked May 22 '10 at 01:18 AM

Mattivc gravatar image

Mattivc
1.7k 55 60 67

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

Best solution is to place a second camera on the scene and put the gun in front of the other camera, set the gun to a layer of it's own and make the second camera only render the gun layer, set the camera to a higher depth than the main camera so that the gun renders over the main view and set it to depth cull so that it doesn't completely hide the main camera.

The result is that the gun will always appear above everything else. If you wanted to have the gun get shaded by lights near the player you can place the second camera as a child of the main camera so that the gun and camera move around with the player.

more ▼

answered May 22 '10 at 01:27 AM

spinaljack gravatar image

spinaljack
9.1k 18 31 91

This is also how I render special HUD elements like way point arrows and minimaps.

May 22 '10 at 01:28 AM spinaljack

Hi there,

I am trying to set this up but my secondary camera seems to be covering the main one. As far as I can see I have set it to only render one layer and also it has culling on to minimum distance. Have you any idea what I am doing wrong?

Aug 22 '11 at 02:14 PM Wiplash

The second camera must be a child of the main camera and must have "mouse look" too.

On the Second Camera:

  • Clear Flags = Depth Only
  • Culling Mask = "New Layer Only"
  • Depth = 1
  • The rest as default

On the Main Camera:

  • Culling Mask = Everything except the new layer

...perhaps this can help you.

Oct 25 '11 at 07:32 AM Edyvargas
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3014
x1175
x276

asked: May 22 '10 at 01:18 AM

Seen: 6110 times

Last Updated: Oct 25 '11 at 07:32 AM