- Home /
Help: A collider attached to the character controller of a FPS does not collide
Hi all, I want to make a FPS and I have added a gun to the First Person Controller of the standard assets. I don't want the gun passes trough the walls, so I have attached a collider to the gun but it does not work.
I have found a similar post but I don't understand how to apply the solution, http://answers.unity3d.com/questions/9168/why-wont-my-box-collider-collide
Thanks!
Answer by Peter G · Dec 07, 2010 at 09:52 PM
For guns, there is a better way to do it. Add a second camera on top of your main camera that moves around with it.
Then:
Set the depth of the second camera to 1, and the first 0.
Create a new layer for your gun.
In camera 2 set the culling mask to only your gun layer, and set the clear flags to depth only.
In Camera 1, set the culling to all but the gun layer.
Now your gun will always be drawn on top of everything else so you don't have to worry about it clipping through the environment.
I have tried it and it works great. Nevertheless i still don't understand why the collider option does not ok. Thank you very much Peter!!!
It has to do with how Unity calculates physics. If you use CharacterController.$$anonymous$$ove, Unity does not calculate collisions for colliders in its children. You could try adding a rigidbody to your child collider, but I don't believe it would make any difference.