Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Sylario · May 25, 2011 at 03:13 PM · collision

Can you have different collision box type with one gameobject.

I am doing a 2D game with Unity.

I have a character that is a plane with a collision box around. I tried to make it contain an empty object (drag and drop a gamobject on another one it appear inside, do not know how it is called) with another collision box.

But the new collision box trigger the OnCollisionEnter from the root gameobject. I wanted to be able to differentiate colission depending wich box was hit.

Is it possible to have collision elements triggereing different responses for the same logical object?

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 pyro · May 25, 2011 at 04:06 PM

You could do something like this:

 //added to child
 function OnCollisionEnter(c : Collision)
 {
     if (c.gameObject.transform == transform.parent) return;
     
     //rest of code
 }

or

 //added to parent
 function OnCollisionEnter(c : Collision)
 {
     if (c.gameObject.transform.parent == transform) return;
     
     //rest of code
 }

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 Sylario · May 25, 2011 at 05:43 PM 0
Share

gameobject return the object that collided with me, not the collider itself. Beside, the OnCollisionObject of the children object is never triggered, it seems the parent has some kind of priority.

avatar image pyro · May 25, 2011 at 11:37 PM 0
Share

the code above is checking "is the object that collided with me my parent? if so exit out early" and you would add that version to the child; the second code checks "am I the parent of the gameobject I collided with? if so exit the function early" and you would add that version to the parent, it's either or you would not use both. Also you can use physics layers in Edit->Project Settings->Physics

avatar image Sylario · May 26, 2011 at 02:35 PM 0
Share

Ok, but it is a "did i collide with myself" situation. Here i am colliding another object, and i want to know if it is the parent or the child that has been touched by another object non related to my gameobject.

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

A node in a childnode? 1 Answer

support not detected collision and Leasehold 0 Answers

How to add to a 3D object's length through code? 1 Answer

Simple collision? 2 Answers

Collision between two sphere game object 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