FPS gun clippes through walls

My gun goes through the walls I have a game object box with a mesh collider on it bit it. It did not fix my problem. Could somebody tell me to add a collider that is something other than a mesh collider or box collider

Thanks

The following was part of an answer I made to address another question.

I'll put in that last bit because it's a sweet trick to know.


Avoiding a Clipped Gun

This will have the gun still visible even though it passes though walls and objects.

  • Add a new layer and name it "Gun Layer" or equivalent.
  • Place your gun in the gun layer.
  • Create a new camera and rename it "Gun Camera" or equivalent. [ GameObject -> Create Other -> Camera ]
  • Remove the gun camera's audio listener, flare layer, and gui layer components. They will be handled by the Main Camera.
  • Make the camera component's clear flags Depth Only, culling mask only the gun layer, and change the depth to be higher than the main camera's.

Adjusting the Crosshair

This is a pretty neat trick to finding the center of your screen, and thus moving your crosshair to the right place.

  • Switch to the game view. The larger your game view the more accurate your placement will be.
  • On your Gun Camera change its field of view to maximum. This will force the perspective to squeeze your gun directly into the center of the screen! My gun turned into one pixel.
  • Now using your gun as the center, position your crosshair so that its center is pointed exactly at the single pixel (The gun). Also, because of the gun layer camera, the gun will be drawn on top of the crosshair. So long as the gun's single pixel can stand out when compared to the crosshair, you will see it.
  • Once done placing the crosshair, go back and return the gun camera's field of view to normal (Roughly 60).

And there you have it! By now you should have:

  1. A crosshair centered exactly at the middle of the screen.
  2. A gun that doesn't get obscured by objects the player would use as cover.

I hope this was helpful! :D

Please search for this next time you have this problem. It has been answered many times before.

Put your gun in a separate layer than everything else. Create a second camera that has its culling mask set to only draw that layer and have the clear flags to depth only.

Then have your main camera underneath it.

And there you have it. You gun will always be drawn on top of everything else.

  1. Add a new camera, put it in the same position as the main camera, and make it a child of the main camera, so it always looks in the same direction.

  2. Select your gun, add a new layer called (“Gun”) or anything you wanna name it. Then with your gun selected, change it to that new layer.

  3. Go to the new camera’s properties, and under Culling Mask options, first, select “None” to clear. Then again, under Culling Mask Options, select “Gun”, or whatever you named your layer.

  4. Under Clear Flags, select “Depth Only”

  5. Now for Depth, set to “1”.

  6. Set the near clip plane to 0.01, and far to 5, or however far out your gun’s object goes.

Now your gun should not go through walls or any other objects. Any problems, email me and I will do this step by step with you to make sure you get it working :slight_smile: Clunk47@Gmail.com

I always just added a collider on to the gun... It's always worked for me...

And Yes, please www.google.com your answers, also, here's a custom search for Unity with Google...

http://www.google.com/cse/m?cx=002470491425767499270:iugs1ezlsfq&cref=&theme=DEFAULT

All the best.

hey zylay i have add a layer in the upperright next to layout i think thats what you mean. end i have get my gun in to this layer i have setup a new camera but my weapon stilll goes treu everyting is thare a way that i can do this with more explained i know what your trying to tell me bud i dont know unity so well am djust a starter 3ds max is my ground but tanks for your time anyway