Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by robbie696 · May 17, 2015 at 08:20 PM · unity 5collisionwallsfirst person shooter

Gun goes through walls (FPS)

Hey, i recently started working on a First Person Shooter. I added the FPController and added a shooting gun. The only problem i still have, is that my gun can go through walls. I tried the different layers/cameras method but i dont know for sure if it works in unity 5 or i just did something wrong.

So how can i fix this problem? (working in unity 5 personal)

Thanks,

me

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 Cherno · May 08, 2018 at 01:29 PM 0
Share

You don't need two cameras. Just scale the viewmodel (that gun the player sees from his or her perspective) to a fraction, like 0.01, and palce it accordingly. If placed correctly, there will be no difference between a normal-sized gun and the tiny one, but the tiny one will sit completely inside the player's collider and thus will never go through any walls.

avatar image screenname_taken Cherno · May 08, 2018 at 01:36 PM 0
Share

You need to be really careful then that you don't place the gun too close to the camera to clip it through the near clipping plane, And you shouldn't have the near clipping plane set to 0. also i'm thinking that perhaps there will be certain situations that you'll perhaps get some inconsistencies with shadows and lighting. Like the camera being just inside a shadow area, and you gun should be half in shadow and half in light. If it's too tiny and placed too close to the camera, won't it be all in shadow?

avatar image Cherno screenname_taken · May 08, 2018 at 04:30 PM 0
Share

That problem might theoretically exist, but I doubt it will become apparent in actual play.

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by screenname_taken · May 17, 2015 at 08:36 PM

You place the gun in its own layer, and you create a camera that only renders the guns. Then you change that camera's depth number to something higher than the main camera's.

Comment
Add comment · Show 5 · 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 Stavros-Dimou · May 08, 2018 at 12:53 PM 0
Share

But if I do that, the camera with the higher depth number just so only the gun and nothing else. The images of the two cameras doesn't blend.

avatar image screenname_taken Stavros-Dimou · May 08, 2018 at 12:59 PM 1
Share

You need to change the "culling mask" flag on the gun camera and set it to only render the gun. $$anonymous$$ake a custom layer called "gun", and set your gun in that one. Then set the camera cull mask to only that. So it only renders the gun. It should render on top of the main camera with only the gun.

avatar image Stavros-Dimou screenname_taken · May 08, 2018 at 02:09 PM 0
Share

Thank you. Now if you can, please answer one more thing: I was using Unity's standard Post Processing Stack on the main camera. Now on the other camera that has only the weapons, they have too much aliasing. :( But if I add a PostProcessingBehavior to this camera, the result is distorted image, no matter if I have it on or off on the other camera. I tried using $$anonymous$$SA but it didn't do anything. Is there any way to have the images of both cameras anti-aliased without artifacts / distortions ?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Sphere (player) flattens/deforms when going on a moving platform. 0 Answers

How to change fall delay of a gameobject by time? 2 Answers

How to make melee weapons engage with enemies? 0 Answers

Cannot line up sights when crouching (FPS Game) 0 Answers

How to count from 2nd collision 1 Answer


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