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 dipmo13 · Oct 25, 2013 at 04:44 AM · c#destroyshootingoncollisionentercollide

How can I make an object invulnerable to collision with a specific object?

I am making a StarFox like game. In the game meteors are hurtling towards the characters ship, if the ship collides with a meteor the ships current health decrease. However, when I shoot the ships gun the bullets also collide and hurt the ship causing it to destroy itself. How can I make the ship invulnerable to the bullets but still take damage from the meteors?

Here is my code if it helps at all...this method is in a script for the ships attributes which declares the ships health and the amount of damage the ship takes from a collision.

 void OnCollisionEnter()
     {
         // Decreases our current health when hit by an object
         currentHealth = currentHealth - standardHit; //standardHit declares damage taken by collision
         
         // Tests if current health is less than 25
         if(currentHealth < 25)
         {
         // Writes to our debug log
         Debug.Log ("Your health is low!");
         }
         
         // Tests if current health is less than or equal to 0
         if(currentHealth <= 0)
         {
             // Destroys our game object
             Destroy(gameObject);    
         }        
     }
Comment
Add comment
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

1 Reply

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

Answer by dazzsnow · Oct 25, 2013 at 05:53 AM

go to Edit/Project Settings/Physics you will then see Layer Collision Matrix in inspector panel. Give ship a different layer to missile / bullet. untick relevant box's in the matrix.

Comment
Add comment · Show 2 · 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 Owen-Reynolds · Oct 25, 2013 at 07:46 AM 0
Share

Just in case, first step is to make 2 new layers (player, playerBullet?) in the layer menu. Names and numbers don't matter. I think 8 is the first empty layer slot.

avatar image dipmo13 · Oct 26, 2013 at 07:02 AM 0
Share

Wow that was a lot simpler than I thought it'd be haha. But it worked! Thank you!

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

17 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Minor bugs in my gun shooting script 1 Answer

Destorying prefab and instanstiating again? 0 Answers

Distribute terrain in zones 3 Answers

Destroying Cubes With OnCollisionEnter 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