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
1
Question by Redlazer · Jan 27, 2012 at 10:45 AM · collisionraycast

My Weapons Hit My Shields - Best Approach?

Hey guys,

I'm working on a mech game for my final project in school - our mech has this really cool shield, but we have a slight problem: my weapons hit it when I fire.

I'm using a mixture of Raycast weapons and Rigidbody weapons - specifically, a chaingun, a laser, and a rocket.

I know I need to use layers - I'm just having some trouble wrapping my head around it.

For my rockets, I also saw Physics.IgnoreCollision - is that a good way to go? Maybe call it on spawn, and re-enable collision after a few seconds?

If anyone has any other creative solutions, I'd also really love to hear them.

My shields have Back Face Culling off, so they're full 3d objects - hence the hitting of the inside of the shield.

Thanks!

-Fred

Comment
Add comment · Show 2
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 Lo0NuhtiK · Jan 28, 2012 at 07:48 AM 0
Share

Damn... member since last june and still at level 1 karma. That's absurd... I barely made it through three days of the moderation queue crap without logging-off and forgetting about this site altogether. +1 For having infinite patience.

avatar image syclamoth · Jan 28, 2012 at 07:51 AM 1
Share

I once saw someone who had been posting consistently high-quality, informative answers for almost a month, with not a single upvote. Needless to say I fixed that as soon as I could.

1 Reply

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

Answer by syclamoth · Jan 28, 2012 at 06:42 AM

In this case, using a layermask is the way to go.

First off, make sure that all your colliders are on different layers for different kinds of objects. So, have a layer for characters, a layer for enemies, a layer for enemy bullets, a layer for friendly bullets, etc.

Then, go to 'Project Settings / Physics' and check on the matrix which layers you want colliding with which other layers.

For your raycast lasers, it's a bit more straightforward. If you've already set up all your layers (friend, enemy, etc.) you can create a 'LayerMask' which determines which layers the raycast can hit.

The easiest way to do this is to simply declare a public one in your class, so that it shows up in the inspector. Then, use the drop-down list to select the correct layers for your raycasts, and use that layermask in the Physics.Raycast call, using the correct overload (the one that uses a layermask).

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

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

6 People are following this question.

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

Related Questions

Custom Collision Detection 4 Answers

Collision Detection If Raycast Source Is inside A Collider? 4 Answers

Optimization of bullet hit calculation per frame 1 Answer

Raycast Mouse Click On Specific Objects Only 0 Answers

2D Rigidbody Drag with Mouse 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