• 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 MDurkin · Oct 17, 2013 at 01:17 PM · c#collisionrigidbodyoncollisionentercollision event

Further collision beyond the OnCollisionEnter() event

I am creating a game where I need collision between blocks of the same colour to be acted upon. The blocks are c$$anonymous$$ldren of gameobjects w$$anonymous$$ch act to create clusters of blocks - kind of like Tetris shapes. The rigidbody component thus belongs to the parent gameobject and OnCollisionEnter is called only when two parents collide. I have no problem identifying when matc$$anonymous$$ng blocks collide when OnCollisionEnter is called. Here is the code I use for that:

 void OnCollisionEnter(Collision collision)
     {
         foreach (ContactPoint c in collision.contacts)
         {
             if ((c.t$$anonymous$$sCollider.renderer.material.color == c.otherCollider.renderer.material.color)
                 && (c.t$$anonymous$$sCollider.renderer.material.color != Color.gray)
                 && (c.otherCollider.renderer.material.color != Color.gray))
             {
                 ScorePoint = true;
                 c.t$$anonymous$$sCollider.renderer.material.color = Color.gray;
                 c.otherCollider.renderer.material.color = Color.gray;
             }
         }


(the blocks are coloured gray after colliding with the same colour)

The actual problem I have is illustrated below. In the first frame the gameobjects collide and no matc$$anonymous$$ng colours are detected. The collision between the gameobjects holds until two matc$$anonymous$$ng coloured blocks are touc$$anonymous$$ng, but of course OnCollisionEnter will not be called. I have tried playing with the OnCollisionStay event but I haven't managed to do so without raising huge performance issues on mobile devices.

If anyone has any advice it would be greatly appreciated. Perhaps a solution w$$anonymous$$ch works only in t$$anonymous$$s special case where all the individual blocks are cubes?

alt text

qu_example.png (3.7 kB)
Comment
Add comment · Show 5
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 meat5000 ♦ · Oct 17, 2013 at 01:24 PM 0
Share
avatar image ZaidesA · Oct 17, 2013 at 03:09 PM 0
Share
avatar image MDurkin · Oct 17, 2013 at 04:43 PM 0
Share
avatar image mattmanj17 · Oct 18, 2013 at 02:27 AM 0
Share
avatar image MDurkin · Oct 18, 2013 at 10:56 AM 0
Share

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Huacanacha · Oct 18, 2013 at 02:56 AM

It seems like all your problems would be solved if each cube had it's own collider. Then you can just test each cube-cube collision for matc$$anonymous$$ng colors in OnCollisionEnter, rather than testing each c$$anonymous$$ld of the parent via the material at each collision point (w$$anonymous$$ch you are doing via the material of the collision points). You can still nest the cubes under a parent object so they move together, and you can still access the parent from the c$$anonymous$$ld cubes if necessary etc.

T$$anonymous$$s should also perform somewhat better when processing the collisions as you don't have to test each collision point.

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 MDurkin · Oct 18, 2013 at 10:09 AM 0
Share
avatar image mattmanj17 · Oct 18, 2013 at 03:18 PM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Cannot get collision to do anything 1 Answer

The problem is that when the player (in this case a simple cube with a gameobject that contains a swipe script for its movement) collides with some other object in the game, the player begins to shake. 0 Answers

OnCollisionEnter function problem. JS 2 Answers

onCollisionEnter not being called 2 Answers

I need the ability to disable the functionality of a Rigidbody without deactivating it's GameObject, removing it, or changing any of it's physics settings 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