- Home /
Gun goes through walls (FPS)
Hey, i recently started working on a First Person Shooter. I added the FPController and added a shooting gun. The only problem i still have, is that my gun can go through walls. I tried the different layers/cameras method but i dont know for sure if it works in unity 5 or i just did something wrong.
So how can i fix this problem? (working in unity 5 personal)
Thanks,
me
You don't need two cameras. Just scale the viewmodel (that gun the player sees from his or her perspective) to a fraction, like 0.01, and palce it accordingly. If placed correctly, there will be no difference between a normal-sized gun and the tiny one, but the tiny one will sit completely inside the player's collider and thus will never go through any walls.
You need to be really careful then that you don't place the gun too close to the camera to clip it through the near clipping plane, And you shouldn't have the near clipping plane set to 0. also i'm thinking that perhaps there will be certain situations that you'll perhaps get some inconsistencies with shadows and lighting. Like the camera being just inside a shadow area, and you gun should be half in shadow and half in light. If it's too tiny and placed too close to the camera, won't it be all in shadow?
That problem might theoretically exist, but I doubt it will become apparent in actual play.
Answer by screenname_taken · May 17, 2015 at 08:36 PM
You place the gun in its own layer, and you create a camera that only renders the guns. Then you change that camera's depth number to something higher than the main camera's.
But if I do that, the camera with the higher depth number just so only the gun and nothing else. The images of the two cameras doesn't blend.
You need to change the "culling mask" flag on the gun camera and set it to only render the gun. $$anonymous$$ake a custom layer called "gun", and set your gun in that one. Then set the camera cull mask to only that. So it only renders the gun. It should render on top of the main camera with only the gun.
Thank you. Now if you can, please answer one more thing: I was using Unity's standard Post Processing Stack on the main camera. Now on the other camera that has only the weapons, they have too much aliasing. :( But if I add a PostProcessingBehavior to this camera, the result is distorted image, no matter if I have it on or off on the other camera. I tried using $$anonymous$$SA but it didn't do anything. Is there any way to have the images of both cameras anti-aliased without artifacts / distortions ?
Your answer
![](https://koobas.hobune.stream/wayback/20220613195831im_/https://answers.unity.com/themes/thub/images/avi.jpg)