x


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!

more ▼

asked Dec 07 '10 at 09:14 PM

wall gravatar image

wall
3 2 2 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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:

  1. Set the depth of the second camera to 1, and the first 0.

  2. Create a new layer for your gun.

  3. In camera 2 set the culling mask to only your gun layer, and set the clear flags to depth only.

  4. 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.

more ▼

answered Dec 07 '10 at 09:52 PM

Peter G gravatar image

Peter G
15.1k 16 44 137

Thanks! I will try this option

Dec 12 '10 at 11:44 PM wall

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!!!

Dec 18 '10 at 09:29 PM wall

It has to do with how Unity calculates physics. If you use CharacterController.Move, 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.

Dec 19 '10 at 07:07 PM Peter G
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1765
x1198
x1081
x549
x461

asked: Dec 07 '10 at 09:14 PM

Seen: 2070 times

Last Updated: Dec 07 '10 at 09:14 PM