Collision of Ring Objects

I am attempting to come up with a way to detect when one ring object collides with another.

Basically, I have N number of rings all centered in the exact same position. I then have an extremely thin ring that grows and shrinks during runtime (the blue ring) and I want to receive collision detection when this ring “enters” and “exits” any of the larger rings.

1519819--86874--$rings.png

What would be the best way to do something like this? I can usually figure problems like this out but I have to admit I am stumped on this one.

My current logic is just manually getting the min/max size of each ring that the blue ring will collide with and then check the blue rings radius (object scale actually) to see if it matches one of the predetermined min/maxes.

The problem is that I need to provide logic that will allow the collision detection of the blue ring w/ any other ring when the other rings are dynamically generated. Meaning, the above image might be one scenario of ring layout but the next time there might be 2 green rings fatter than the one above and only 1 thinner red ring.

I started down the path of creating a simple “ring” fbx object and then importing that into my scene as a prefab. My idea was that at runtime I would create the rings the size I needed at the time (by scaling them) and placing them all in the same position. I would then create the blue ring, place that in the center of all of them, and then scale it watching for OnTriggerEnter/OnTriggerExits from the collisions.

Where I am getting stuck is applying a collider to each of these rings. I cant use a primitive box or sphere collider due to the shape (i.e. they are hollow). I then try to add a mesh collider to each of them and a rigidbody to JUST the blue ring (with kinematic enabled so I can get one of the trigger responses from the collision matrix) but I am receiving the “Actor::updateMassFromShapes: Compute mesh inertia tensor failed for one of the actor’s mesh shapes! Please change mesh geometry or supply a tensor manually!” exception.

On top of all that, I am still not convinced this is the best approach to this problem. The ending result needs to run on mobile devices and I am worried that using mesh colliders in this fashion will be a problem for those platforms.

Any suggestions and help would be greatly appreciated!

PAR

So a little further investigation shows that ordering the component additions solves the Mesh Collider exception along with making the collider itself a trigger (which is what I want anyway). If I add a rididbody first and then the mesh collider that error goes away.

As for solving the larger problem, I’m suck with the issue of “Mesh Colliders cannot collide with each other unless they are convex”. Since all objects in this scene are rings and must be hollow I am not quite sure if this is the solution I am looking for…

PAR

Whelp, once again its come down to making things too darn complicated!

Solution, for anyone who might want to know in the future, was to completely forego trying to make the rings themselves collidable.

Basically, I took each of my rings and added a small box collider to each of them. I then moved the box collider to the very edge (horizontally center) of the ring portion and made the collider the width of the ring. I then created them as prefabs.

Now at runtime, depending on whatever logic dictates the number, type and size of rings, I just instantiate the correct prefab, scale it to what it needs to be and place it in the center of the other rings. Since the box collider is a child of the ring it scales exactly the same way as its parent.

Finally, as the “growing/shrinking” ring has the same type of box collider but also a rigidbody that is kinematic, I now get the correct Enter, Stay and Exit calls whenever it hits one of the outter rings.

1520424--86965--$rings2.png

PAR