Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Andrew85 · May 25, 2011 at 10:17 PM · collisiondestroyprojectiledetection

Destorying an object when it hits the ground

Hi, I'm trying to get my projectile "Shell" to be destroyed both when it hits the opponent, and if it misses and hits the floor. As it is now, it does print out but doesn't get destroyed. I'm sure I overlooked something small or put something in the wrong place. Any help would be appreciated!

     function OnCollisionEnter(collision : Collision)
 {
 print( "floor");
     if (collision.gameObject.tag == "Shell")
     {
         Destroy(gameObject);
     }
 }
Comment
Add comment · Show 1
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 Andrew85 · May 25, 2011 at 10:18 PM 0
Share

I should also add that it does get destroyed upon hitting and dealing damage with the opponent, just not the floor.

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Joshua · May 25, 2011 at 10:52 PM

First of all, I'd add this script to the shell, not the floor. Let each shell check 'am I hitting the floor' and not the floor 'am I being hit by a shell'. I'm not sure, but I could imagine that if two shells enter collision with it during the same frame, only one will get destroyed. It would also seem that in the script you posted you're destroying the floor, not the Shell. Or you're checking the shell, not the floor - it's hard to know what if I don't know if the script is attached to the floor or the shell.

This is how I would do it. Attach this script to the shell and tag the floor "Floor".

 function OnCollisionEnter(col : Collision) {
     if (col.gameObject.tag == "Floor") {
         Destroy(gameObject);
     }
 }
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 Andrew85 · May 25, 2011 at 11:07 PM 0
Share

Tried this, and the shells still aren't being destroyed. The shells are rigid bodies, not sure if that matters though.

Thanks for the help by the way!

avatar image Joshua · May 25, 2011 at 11:10 PM 0
Share

Well this code surely works. Do you have the floor tagged Floor (check capitalization!) do the shells have a collider? Does the floor have a collider?

avatar image Andrew85 · May 25, 2011 at 11:13 PM 0
Share

Shells have colliders, floor has a collider, floor is tagged. The tag is in lowercase, but I changed the code to match. I can try making them all Capitalized though.

avatar image Joshua · May 25, 2011 at 11:16 PM 0
Share

No that doesn't matter, at long as the tag you're checking and the tag is has are the same. Is this script attached to the bullets, not the floor? o.O

avatar image Andrew85 · May 25, 2011 at 11:20 PM 0
Share

Oh man...lol. Got it. I have individual pieces making up an area of the floor and grouped into "hill", "dip", "straight" etc. I tagged them as a whole without realizing that each individual piece needed the tag.

It does work now. Thaks a ton man!

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

2 People are following this question.

avatar image avatar image

Related Questions

Trouble with raycast hitting a tagged object 0 Answers

Collision Detection Issue with SetActive(false) not working 2 Answers

collision wont work 1 Answer

Create hinge joint 2D by collision 2 Answers

Collision Detection for a Prefab? 3 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