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 snowconesolid · Jan 07, 2012 at 12:38 AM · destroychildoncollisionenterarmature

Object wont destroy on collision with another object

For some reason my object is not destroying when it collides with another object.

heres what im trying to do, my character is holding a sword, the sword object has a collider, so I want to destroy objects when only my sword collides with them so I put this script on my sword object:

function OnCollisionEnter (hit : Collision) {

 if(hit.gameObject.tag == "Respawn") { //The object I want to destroy tag = Respawn

     Destroy(hit.gameObject);

 }

}

It doesn't work though. for testing purposes I removed the script from my sword and applied it to my character and changed the function to OnControllerCollider and it worked perfect, the only thing is thats not what Im trying to do, I don't want the object to destroy when the player touches it, I want it to destroy when the sword touches it. Im not sure why its not working when I use OnCollisionEnter and apply the script to my sword.

if it means anything, my sword is a child of my characters armature, so when my character moves his arm, the sword moves with it in the same direction. Maybe because its a child it could be causing the problem?

Other information, my sword just goes right through the object I want to destroy, but both the sword and the object I want to destroy have colliders on them.

Thanks for any help in advanced.

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 Posly · Jan 07, 2012 at 12:53 AM

You need a rigidbody on stuff that you want to detect collision on. Also if you don't want the enemy to be destroyed when the player just touches the sword I'd use an animation event, and in the animation event it creates a temporary trigger in front of your character and whatever is in that trigger will be destroyed. So let's say the person presses space it would play that animation and the animation event would create a temporary trigger box and just attach a OnTriggerEnter function onto the trigger box thingy and whatever is in that box will be destroyed. It's kinda confusing I guess but it would make the game more professional and stuff.

Comment
Add comment · Show 1 · 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 snowconesolid · Jan 07, 2012 at 01:38 AM 0
Share

Thanks it worked, all I was missing the rigid body. I like the Trigger idea and yes that defiantly does sound a lot more professional. But to keep things simple ill just do it like this for now :)

Also I was thinking maybe to keep it even more simple I can achieve the same effect that you mentioned but with a different way.

I was thinking to disable the collider using collider.enabled = false;

and then using an If statment to check if the space key is pressed, if it is pressed then

collider.enabled = true;

then later it would set the collider back to false and only enable it to true when space is pressed, but for some reason that did not work,

the collider stays false even after I push space, not sure why.

Thanks anyway for the help.

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

A node in a childnode? 1 Answer

Player object still gets destroyed even when shields up 1 Answer

Correct way to destroy GameObject with UnitySteer Steering attached 1 Answer

Should I use Destroy() or SetActive(false)? 1 Answer

Make object A parent of object b 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