- Home /
object collision attatched to camera
How do i fix this common problem where an object that's attatched to the main camera will go through walls. I am makeing an fps, How do I stop the the gun from going through objects.
Comment
Best Answer
Answer by e-bonneville · Apr 01, 2011 at 07:59 PM
Here's a good solution, although it's slightly involved. Do your best to follow each step exactly.
- Create a new layer by clicking on Layers/Add Layer from any object. Name it "GunLayer".
- Put your gun on this layer by clicking Layers/GunLayer from the Layers dropdown while on the gun object.
- Create a new camera, and uncheck all the components except for the Camera component. Name it "Gun Camera"
- Then, still on the Gun Camera object, select the culling mask dropdown, and select GunLayer. This makes it so the camera will render only objects on the GunLayer layer.
- Set Clear Flags to Depth Only. This means it won't render a background or skybox or anything, just the gun.
- Move your Gun Camera object to the exact same coordinates as the main camera, and make it a child of the main camera. Getting it to the exact same coordinates is crucial.
That's it, your gun will no longer go through walls.
If this works for you, I wouldn't $$anonymous$$d an upvote as well. :P