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 Bagul3 · Jan 04, 2014 at 10:16 PM · c#oncollisionenter

Using OnCollisionEnter with cube

Hi I am using OnCollisionEnter with a cube, but anytime the player(Which is just a capsule for now) touches the cube nothing happens. I am looking the cube to be destroyed whenever the player touches it. Both the player and the cube have ridge bodies, both of them do not have is Kinematic checked. Any help would be great :)

void OnCollisionStart (Collision col)

{

 if (col.gameObject.name == "PlatformBroken") 

 {        
 Destroy(col.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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by NightmarexGR · Jan 04, 2014 at 11:23 PM

Instead of:

 void OnCollisionStart (Collision col)

Use:

 void OnCollisionEnter(Collision col)

Hope it works.

~NightmarexGR

Comment
Add comment · Show 3 · 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 Bagul3 · Jan 04, 2014 at 11:42 PM 0
Share

Hey man, I tired that but it still didn't work :(

avatar image NightmarexGR · Jan 04, 2014 at 11:53 PM 0
Share

Then i have no idea sorry

avatar image Bagul3 · Jan 04, 2014 at 11:54 PM 0
Share

No problem, Thanks anyway :)

avatar image
0

Answer by AlucardJay · Jan 05, 2014 at 12:08 AM

Collider : http://docs.unity3d.com/Documentation/ScriptReference/Collider.html

  • OnCollisionEnter OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.

  • OnCollisionExit OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.

  • OnCollisionStay OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.

  • OnTriggerEnter OnTriggerEnter is called when the Collider other enters the trigger.

  • OnTriggerExit OnTriggerExit is called when the Collider other has stopped touching the trigger.

  • OnTriggerStay OnTriggerStay is called almost all the frames for every Collider other that is touching the trigger.

OnCollisionEnter : http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html

Description : OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.

Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.

^^ is this true for your objects?

Comment
Add comment · Show 4 · 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 AlucardJay · Jan 05, 2014 at 12:09 AM 0
Share

http://www.unity3dstudent.com/2010/07/beginner-b01-basic-collision-detection/

avatar image Bagul3 · Jan 05, 2014 at 12:13 AM 0
Share

Yeah my player has a rigidbody attached, and so does the square. Does it matter if I have use gravity not checked?

avatar image AlucardJay · Jan 05, 2014 at 12:17 AM 0
Share

Add a debug in your collision event to find out if the collision is taking place, and the names of the gameObjects involved :

 void OnCollisionEnter (Collision col)
 {
     Debug.Log( gameObject.name + " just collided with " + col.gameObject.name );
     if (col.gameObject.name == "PlatformBroken")
     {
         Destroy(col.gameObject);
     }
 }


also in future, please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.

  • Read this page : http://answers.unity3d.com/page/newuser.html

  • Watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers

avatar image Bagul3 · Jan 05, 2014 at 12:17 AM 0
Share

I figure it out, it was to do with the mesh size of my character it wasn't actually touching the square! Thanks for the help everyone :)

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

20 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 avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

[URGENT!!!] OnCollisionEnter is not working; need help to figure out if I've missed something or if it's a Unity 5 bug. 1 Answer

OnCollisionEnter not working 1 Answer

How to make gameObject make only one collision 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