Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jul 24, 2014 at 07:59 PM by duck for the following reason:

Duplicate Question: http://answers.unity3d.com/questions/39420/gun-goes-through-wall-in-a-fps.html

avatar image
3
Question by Wesley S · Jan 04, 2011 at 09:28 PM · fpsgunshooterclippingflagged-for-close

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

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NinjaSquirrel · Jan 04, 2011 at 09:34 PM 3
Share

Please use proper grammar when asking a question here. You will be respected here much more if you do that, thanks :)

avatar image Peter G · Jan 04, 2011 at 09:47 PM 0
Share

Fixed it. Voted to close since it pops up so much. Just chose the first dupe I could find.

avatar image AnselmeUnity · Mar 03, 2014 at 01:27 PM 0
Share

And if you have the AimDownSight script attached to the $$anonymous$$ain Camera, in main camera culling masks don't forget to disable the "Gun" Layer so when you aim you don't have wierd things... ^^

5 Replies

  • Sort: 
avatar image
23

Answer by Zylar · Jan 07, 2011 at 05:42 AM

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

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wesley S · Jan 09, 2011 at 01:55 AM 0
Share

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

avatar image eklumt · Jan 16, 2014 at 09:38 PM 0
Share

Awesome, works great, I couldn't have imagined it would be that simple but it makes perfect sense when you explained it. If only I could upvote!

avatar image Lunatix · Dec 04, 2014 at 10:55 PM 0
Share

A little addition: This does not work out of the box when the rendering path is set to deferred rendering - just force forward rendering for the second camera.

avatar image RElam · Jan 28, 2015 at 08:51 PM 0
Share

Unfortunately this doesn't work great if using effects using depth buffer like AO and edge detection, as the second rendering will clear the depth buffer. Ideally UT would supply the ability to clear the Z buffer, but not the depth buffer.

avatar image crackyourspeakers · Sep 25, 2017 at 11:01 PM 0
Share

so when I add the layer to gun it brings up a window thats says " do you want to make child for all? or just this object" when I click make all it makes a double of the gun, but when I tried it for just the object it doesnt work, still goes through walls. Ive noticed that when I selected make all child and it doubles the weapon, that one of the doubles actually work but the other doesnt.

Show more comments
avatar image
4

Answer by Clunk · Sep 17, 2011 at 07:12 PM

  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 :) Clunk47@Gmail.com

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

Answer by Peter G · Jan 04, 2011 at 09:44 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Justin Warner · Jan 04, 2011 at 10:42 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Wesley S · Jan 09, 2011 at 01:55 AM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

damage system 0 Answers

How to Implement First Shot Accuracy? 2 Answers

Fps game gun reloading problem 1 Answer

Gun still clips through the wall despite layer masks being applied 1 Answer

Any problem with using real weapons in a FPS game? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges