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 Default117 · May 15, 2012 at 11:43 PM · collisionrigidbodyoncollisionenter

OnCollisionEnter not working

I'm having some issues with a certain use case when two objects touch on screen, but do not "collide".

The scenario is, that the bottom of the screen has shapes. When i click on the shape and drag, it generates a new shape and follows the mouse cursor, while following the mouse, the rigidbody is set to kinematic. When the shape is let go, i turn on gravity to make it drop to the bottom of the screen hitting a floor surface. When it reaches resting point, i turn it back to kinematic so that it stays in that position.

The problem arises when i create another object and try to drag it into the object on the floor. For some reason it doesn't detect collisions between these two objects. However. If i drag two objects simultaneously and make them touch their OnCollisionEnter scripts get fired.

Is there a limitation i am overlooking? Can two kinematic objects not collide?

Cheers

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

3 Replies

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

Answer by hathol · May 15, 2012 at 11:53 PM

From http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html "Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached." You could maybe use OnTriggerEnter instead.

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 Default117 · May 15, 2012 at 11:55 PM 0
Share

Excellent. Thanks for that, i must have overlooked that line =/ I'll try a combination of triggers and colliders to see if i can get the desired effect.

avatar image Default117 · May 16, 2012 at 12:03 AM 0
Share

Alright, so that does allow me to test two kinematic objects if they collide. But then the issue comes where you cannot test between a kinematic and a gravity based object anymore, because one now has to be a trigger to test against kinematic. It all gets too confusing and complex for what it needs to be.

Your answer did provide enough info for my question however =] Unfortunately it is not the optimal solution for the problem i'm trying to solve.

avatar image hathol · May 16, 2012 at 12:27 AM 0
Share

Can't you do somthing like:

 While draging: IsTrigger = On, $$anonymous$$inematic = 0n.
 While falling: IsTrigger = Off, $$anonymous$$inematic = Off.
 Else: IsTrigger = Off, $$anonymous$$inematic = On.

And then use OnTriggerEnter while it's dragged and OnCollisionEnter for every other state?

avatar image dpk · Jun 22, 2013 at 05:19 PM 0
Share

@hathol This doesn't seem to be the case in 4.1. I have two gameobjects that are colliding (one can't pass through the other), and one has a non-kinematic rigidbody. Despite all of that, OnCollisionEnter is not called.

avatar image
6

Answer by kfirmon · Sep 26, 2015 at 05:58 PM

make sure you're spelling it right and case sensitive (OnCollisionEnter, OnTriggerEnter), spelling it wrong will not cause an error so you won't know.

Comment
Add comment · Show 5 · 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 pmfrdias · Mar 18, 2016 at 12:53 AM 1
Share

Thank you for that comment :D I was going crazy with this problem and noticed that I wrote "onCollisionEnter" ins$$anonymous$$d of "OnCollisionEnter". Thank you thank you thank you!

avatar image kfirmon pmfrdias · Mar 18, 2016 at 03:08 AM 0
Share

happy it helped :) I was going through the same thing myself...

avatar image donbright · Jan 11, 2017 at 04:39 AM 0
Share

thanks for this. lol i have been program$$anonymous$$g off and on since 1986 and i still managed to mess this up. So used to python, C++, etc, where method names almost never start with capital letters.

avatar image kfirmon donbright · Jan 13, 2017 at 09:33 AM 0
Share

you're most welcome :) happy to help. have a great weekend my friend :)

avatar image bence0302bence · Aug 19, 2017 at 07:05 PM 0
Share

Thank you this helped <3

avatar image
0

Answer by Soniya_unity · Jul 21, 2017 at 08:09 AM

void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag != "Enemy" && col.isTrigger != true) { Destroy(gameObject); } }

you have to write Collision2D not Collider2D .. :)

https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html

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 Soniya_unity · Jul 21, 2017 at 09:07 AM 0
Share

obviously it through error because this is collision not trigger, you wants trigger then write this

void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag != "Enemy" && col.isTrigger != true) { Destroy(gameObject); } }

https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnTriggerEnter2D.html

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

12 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

Related Questions

CharacterController and Normal rigidbody Box Collider Collision issues 0 Answers

OnCollisionEnter and rigidbody problem 1 Answer

onCollisionEnter doesn't work without RIgidbody? 1 Answer

Rigidbody not calling OnCollisionEnter 1 Answer

Two Character Controllers Colliding... 0 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