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 DrZoop · Oct 19, 2014 at 04:13 AM · physicsrigidbodycollideroncollisionenterhit detection

Need second pair of eyes: rigidbodies with colliders not firing OnCollisionEnter yet again...

It's gotta be something with the parent/child relationships:

Nothing fancy here:

 GameObject 1:
     -Capsule collider with Is Trigger DISABLED.  I want physics reactions.
     -Rigidbody with Is Kinematic DISABLED.  I want physics reactions.

 GameObject 2:
     -Rigidbody with Is Kinematic DISABLED.  I want physics reactions.
     ColliderGameObject:
         -Capsule collider with Is Trigger DISABLED.  I want physics reactions.
         -Script
     AnotherColliderGameObject:
         -Box Collider
         (This is mentioned to demonstrate to you that this is a compound physics object.)
         (No script desired.)


 GameObject 3:
     GameObjectContainer:
         ModelGameObject:
             ModelGameObject:
                 -Box Collider with Is Trigger DISABLED.  I'm not doing anything with triggers.
                 -Script
             Another ModelGameObject:
                 -Box Collider with Is Trigger DISABLED.  I'm not doing anything with triggers.
                 -Script
             A bunch more ModelGameObjects with box colliders but without scripts.
                 

GameObject 1 -> GameObject 2 = FAIL. No collision detected. Why!?

GameObject 1 -> GameObject 3 = SUCCESS. Collision detected, even though there is only one rigidbody between the two objects, and it isn't even on the one with the script!

The difference is that GameObject 2 has a rigidbody where as GameObject 3 does not. If I were a betting man, I would have presumed 1 -> 2 would have worked over 1 -> 3. Hence why I need a second pair of eyes.

Nothing fancy with the script either:

 void OnCollisionEnter(Collision collision)
 {
     Debug.Log("hit it!");
 }

Riddle me that, Batman. Thanks.

(Googling is just leading me to a bunch of cases of people not knowing how to use Unity's physics system. This is some fringe case and I've been looking at the same situation for too long.)

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

Answer by tanoshimi · Oct 19, 2014 at 06:28 AM

"Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached." (http://docs.unity3d.com/ScriptReference/Rigidbody.OnCollisionEnter.html). So that's the second mystery solved: only one object needs a rigidbody attached, and the collision event is sent to both objects involved in the collision. If either implements OnCollisionEnter then they can act upon it.

As for the first mystery, if I understand your hierarchy correctly, you need to move the script onto the parent object:

 GameObject 2:
   -Rigidbody with Is Kinematic DISABLED. I want physics reactions.
   -Script

   ColliderGameObject:
     -Capsule collider with Is Trigger DISABLED. I want physics reactions.

   etc.
Comment
Add comment · Show 2 · 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 DrZoop · Oct 19, 2014 at 04:15 PM 0
Share

"Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached." << I wasn't sure if that meant anywhere in the hierarchy chain or literally side-by-side. After posting the question I ended up working on other on-hit type stuff with compound objects and noticed that the script would work if it was side-by-side with the rigidbody. I guess side-by-side it is! Thanks for being my second pair of eyes.

avatar image DrZoop · Oct 19, 2014 at 04:17 PM 0
Share

A shame you can't put the scripts on the collider you want to specifically test though, for simplicity's sake. I suppose I will have to dig through the Collision's Collider property to figure out if the right thing was hit.

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

Applying proper drag and center of mass for a vehicle 1 Answer

When and when not to use kinematic rigidbody? 2 Answers

OnTriggerEnter - Objects pass through each other? 3 Answers

Is it possible to tell Unity physics to ignore a collision at collision time? 1 Answer

Raycaste vs trigger Colliders & Rigidbody performance 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