x


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.

more ▼

asked Apr 01 '11 at 07:45 PM

Alex 9 gravatar image

Alex 9
79 19 18 20

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

1 answer: sort voted first

Here's a good solution, although it's slightly involved. Do your best to follow each step exactly.

  1. Create a new layer by clicking on Layers/Add Layer from any object. Name it "GunLayer".
  2. Put your gun on this layer by clicking Layers/GunLayer from the Layers dropdown while on the gun object.
  3. Create a new camera, and uncheck all the components except for the Camera component. Name it "Gun Camera"
  4. 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.
  5. Set Clear Flags to Depth Only. This means it won't render a background or skybox or anything, just the gun.
  6. 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.

more ▼

answered Apr 01 '11 at 07:59 PM

e.bonneville gravatar image

e.bonneville
5.7k 100 116 165

If this works for you, I wouldn't mind an upvote as well. :P

Apr 02 '11 at 03:05 AM e.bonneville
(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:

x3014
x2504
x2093
x80
x34

asked: Apr 01 '11 at 07:45 PM

Seen: 1391 times

Last Updated: Jul 19 '11 at 01:02 AM