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 TMPxyz · Sep 13, 2014 at 06:06 AM · collisionphysicsrigidbodycollider

Collision.collider returns wrong object

Hi, all,

I just encountered a weird Physics problem, I don't know if this is by design, so I would appreciate it if someone could tell me the definite answer.

Say, I have a hierarchy like this, a root object with two child objects;

 + Root (Kinematic Rigidbody)
 --+ Core  (Sphere collider)
 --+ Platform (Box collider)

and when I drop another cube with rigidbody+collider on the Core, I check the info passed by OnCollisionEnter(Collision),

it was

 Collision.collider : Platform  <-- should be Core
 Collision.gameObject : Root
 Collision.transform : Root

Everything will be right if I put rigidbody on both the Core & Platform.

Is it a bug?

Env: Unity 4.5.2f1 + Win7

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

Answer by Dhiru · Sep 13, 2014 at 06:27 AM

You can get the collider object by a tag or by name. Then call void OnCollisionEnter(Collision collision) method.

Now the Script should be like this:

 void OnCollisionEnter(Collision collision) {
 if(collision.tag =="otherGameObjectTag"){
 do some stuff here
 }
 if(collision.name =="otherGameObjectName"){
 do some stuff here
 }
 }

Hope this will work

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 TMPxyz · Sep 13, 2014 at 07:00 AM 0
Share

Hi, Thanks for the reply. :)

Huh...Are you sure there're tag and name fields on Collision type? Because they're not on doc, and I checked the source, Collision doesn't have the "tag" or "name" within it.

avatar image Dhiru · Sep 13, 2014 at 07:13 AM 0
Share

sorry,I made a mistake. need a small change.

 void OnCollisionEnter(Collision collision) {
 if(collision.collider.tag =="otherGameObjectTag"){
 do some stuff here
 }
 if(collision.collider.name =="otherGameObjectName"){
 do some stuff here
 }
 }

Now try this

avatar image TMPxyz · Sep 13, 2014 at 08:34 AM 1
Share

Thanks :) but as I said in question, the problem I encountered is that the "collision.collider" is not the right collider.

In my example, I expected collision.collider.name == "Core", but it turns out to be "Platform";

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

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

Related Questions

Tossing an object with the correct force at any distance from another so that it collides with the other 1 Answer

Camera gets flung off of the map when the player collides with certain objects. 0 Answers

Rigidbody doesn't rotate after collision 3 Answers

Velocity data from OnCollisionEnter is delayed (incorrect) 3 Answers

Rigidbody necessary to use collision detection 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