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 asimov · May 20, 2012 at 05:27 PM · collisiondestroyontriggerenterbulletoncollisionenter

Have bullets be destroyed when they collide with ANY collider

Hi,

Was wondering if there is a way to have a bullet (with collider) be destroyed when it hits any object's collider (enemy/wall, etc), rather than specifying an individual collider.

What's the best method to use? OnCollisionEnter, OnTriggerEnter, Ray casts, and how?

Thanks

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
3
Best Answer

Answer by Scribe · May 20, 2012 at 05:41 PM

hopefully I'm not mistaken in saying that this will check for any collisions with the bullet

 function OnCollisionEnter(){
      Destroy (gameObject);
 }

Hope that works! Scribe

Comment
Add comment · Show 10 · 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 aldonaletto · May 20, 2012 at 05:44 PM 3
Share

NOTES:
1- place this code in the bullet's script;
2- the bullet must be a rigidbody.

avatar image FLASHDENMARK · May 20, 2012 at 05:50 PM 0
Share

@aldonaletto

Correct me if I am wrong, but the bullet does not need a rigidbody as long as the gameObject it touches is a rigidbody, right?

avatar image Lo0NuhtiK · May 20, 2012 at 05:54 PM 0
Share

@OrangeLightning : I almost asked that also lol ... but figure since they want the bullet to destroy itself when it hit's "anything" , then it's either the bullet has a rigidbody, or would have to make sure "everything" else has a rigidbody on it.

avatar image aldonaletto · May 20, 2012 at 06:13 PM 0
Share

Yes, in theory at least one of them must be a rigidbody - but moving a non-rigidbody object do not awake the hit rigidbodies (the object passes through them), thus it's better to make the bullet a rigidbody.

avatar image KiraSensei · May 20, 2012 at 06:23 PM 0
Share

Actually it's important that only one of the elements has a rigidbody. I f the bullet has one and the wall (for example) has one too, the collision will not be detected. If both have a rigidbody, one has to be convex

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

9 People are following this question.

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

Related Questions

2 objects collide, need to destroy one 2 Answers

Objects do not destroy on Collision 1 Answer

How to only delete one of two collided objects? 1 Answer

How to destroy bullet on collision! 2 Answers

Collision2D error when instantiating a prefab. 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