- Home /
Gun goes through wall in a FPS
Im making a FPS, and the gun will go through walls and stuff. How do I make it like call of duty, where the gun will always be visible, no matter what?
Answer by Eric5h5 · Dec 23, 2010 at 03:27 AM
Put the gun on a separate layer and have it be rendered by another camera, which is on top of the main camera and only renders the gun layer. See the docs (the section called "depth only").
I checked out the link, but i'm still not sure what to do
This method worked, but for some reason dropped my fps quite a bit. Why?
Define "quite a bit"...adding another camera adds some overhead, but it's quite $$anonymous$$imal.
Well, something is wrong but I don't know what. At a guess, make sure you're using layers correctly. You should lose maybe 1fps, if that much.
Answer by lollie009 · Oct 24, 2013 at 06:06 PM
Create new camera and remove standard listener component
Parent new camera to your main camera
Create tag for the gun on layer 11 or another free layer (you'll see why in the next step) and then change the layer from default to the new gun layer created
In the new camera's inspector option, set clear flags to depth only, culling mask to the newly created gun layer and change depth to something like 80 (higher numbers are drawn on top)
go back to main camera and remove the gun from culling mask
I think what lollie009 said was a great answer, i think thats what devs that make games like call of duty do. Thank you for the answer lollie009, amazing!
awesome, alot of people that explain this does not mention to remove the gun from culling mask on the main camera. thank you
Answer by Justin Warner · Dec 23, 2010 at 03:59 AM
You can always put a collider on the tip of the gun... That works for me at least.
Answer by zeuo · Dec 23, 2010 at 05:37 AM
ya the same thing happened to me. u know when u add character controller to ur player and a green capsule appears, just make sure that the gun is inside that capsule. change the radius that worked for me
Answer by GeorgeLuther · Dec 08, 2017 at 02:46 AM
doesn't it technically still clip through the wall though? its just an optical illusion that it doesn't? my prefabs from my weapon still appear on the other side of the wall! I have colliders on my walls and my sphere(gun) and the green-wireframes are slightly larger than the objects. I have checked the physics layers and made sure they are set to recognize each other. The prefab is set to load from an empty child within the body of the sphere.