top of page

Gun and Wall Glitch

If you have worked in an fps game, you must have surely encountered this scenario. What happens here is, if you go close to walls/objects, you gun/hands goes onto the wall/objects. This is clearly shown in the video below.



This arises when you have only one camera to render everything.

This simply can be avoided using 2 cameras.

One camera - should render everything except gun

And the other camera - should render nothing but gun.


Steps to follow:

  1. Create a child camera object, as a child of main camera which you are using for your fps.

  2. Identify the objects which are glitching through the walls. For example - Guns, hands, knife etc. Once you have identified those object, put them all under a custom layer say "Guns". Now all these objects are layered "Guns".

  3. Now for we have 2 cameras - Main camera(For fps) and Child Camera. For Main Camera go to inspector tab and select Culling mask. From that culling mask remove "Guns" layer. This means you are telling main camera to render every object except those objects which are layered under "Guns". So in that camera you don't see these objects.

  4. Now in the secondary camera, all you have to tell that is - to render ONLY those objects which are layered "Guns". You do this by setting "Clear Flags" to - Depth Only and Culling Mask to "Guns".

  5. So now basically you have 2 camera - one is main camera which renders everything but Guns layered objects and Child cam which renders only guns layered object.

So basically "Clear flags" in camera indicates what to use to clear old frame and draw new captured frame on top of it. So clear flag can be skybox,Solid color or depth only.

Skybox: Whenever a new frame has to be rendered the old frame is cleared with given skybox on top of it new captured frame of scene is rendered.


Solid Color: Whenever a new frame has to be rendered the old frame is cleared with given background color on top of it new captured frame of scene is rendered.


Depth Only: When ever a new frame has to be rendered from the old frame only the gameobject with depth are cleared not the old frame itself. So you can clearly observe old frames will be still visible and gameobjects in scene are rendered properly without intersecting.


Don't Clear: Nothing is cleared here. You can see all frames in your game.


As shows in the above example we use depth only in a scenario where we use multiple cams.



These steps will also be shown in the video below.



 
 
 

Recent Posts

See All

Comments


bottom of page