Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Torus collision often fail (rings interpenetration)

Discussion in 'Physics' started by abermann_O, May 1, 2021.

  1. abermann_O

    abermann_O

    Joined:
    Aug 16, 2018
    Posts:
    42
    Hello everybody, I have some rings on the game, and when the player push a button, I apply a force to those rings, besides moving obstacles in the scene (kinematic ones). But from time to time, the rings get across each other, forming sort of a chain. I have no idea what else to try here... is there a safe way to be 100% sure that the rings won´t go through each other, no matter what forces they interact with? I´m using compound colliders on each ring prefab...
    This is my physics setup (although I had test several configurations with no success in 100% avoid interpenetration from the rings, so I suspect maybe a different approach must be made, something like raycasting to test the proximity of other rings, or something like that?)

    Thanks!
    upload_2021-5-2_11-43-2.png
     
    Last edited: May 2, 2021
  2. rubcc95

    rubcc95

    Joined:
    Dec 27, 2019
    Posts:
    222
    Do you have setted the rigidbodies of your rings to Collision Detection Mode = Continuos Dynamic?
     
    abermann_O likes this.
  3. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Are your rings using MeshCollider? If so, those are not meant for movable objects. Non-convex mesh colliders use triangle collision detection, and thus cannot be "sweeper" during movement. Triangle soup colliders also don't have the concept of inside and outside (since it's just a list of triangles), so if two mesh colliders end up intersecting there's no way to figure out how to move them to resolve the interpenetration.

    You need to make your rings' collision using multiple convex colliders instead. Only convex colliders (BoxCollider, CapsuleCollider, SphereCollider) support continuous collision detection, because it's mathematically possible to determine interpretation and to sweep them during movement.
     
    abermann_O likes this.
  4. abermann_O

    abermann_O

    Joined:
    Aug 16, 2018
    Posts:
    42
    Thanks for your kind response, rubcc95, I forgot to attach an image of my rings setup, which is this:

    upload_2021-5-1_14-18-33.png

    In the past, I´ve tried Continuous Dynamic, and it did help, but the rings eventually keep interpenetrating each other
     
  5. abermann_O

    abermann_O

    Joined:
    Aug 16, 2018
    Posts:
    42
    That´s a great explanation, Neto_Kokku, thanks for taking the time to write it, I didn´t know the technical explanation, although I did know I couldn´t use mesh colliders. I´m using a compund collider (already try box and capsule colliders), but the rings keep interpenetrating under certain circumstances .
     
  6. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    467
    I don’t agree that mesh colliders are not meant for moving objects. Obviously non-convex colliders don’t work, but convex ones do and they have perfectly valid applications and are reasonably fast nowadays.

    Concerning the interpenetration that makes the chain separate in certain circumstances: unfortunately chains are even more challenging than ropes. I case your application allows it, please have a look at a particle-based solution. I’m very happy with ObiRope, great team, great code. I’m not affiliated with them in any way.

    they do charge for their asset, however.

    another thing you can try is to decrease the physics time step
     
    abermann_O likes this.
  7. abermann_O

    abermann_O

    Joined:
    Aug 16, 2018
    Posts:
    42
    Thanks for your time to answer my question, tjmaul. Actually, I meant the other way around (sorry about my english): I need the rings to remain aside from each other: when their physics behave wrong, they interpenetrate and form a chain. I´m using a time step of 0.01

    upload_2021-5-2_11-44-20.png
     
  8. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    467
    I should have read your first post more carefully: Without knowing your use-case, I'd suggest making the rings solid. You can use a convex mesh collider for that. Put those colliders on a newly created Ring-Ring layer and configure the physics collision matrix for this layer to just collide with itself.
    Keeping your original collider on the default layer, you still have ring-like colliders but also rings that recover from being pushed inside each other.

    Unfortunately I do not know a way to guarantee that colliders stay separate, no matter how much force is applied. Maybe you could elaborate on your use case?
     
    abermann_O likes this.
  9. abermann_O

    abermann_O

    Joined:
    Aug 16, 2018
    Posts:
    42
    That´s an excellent sugestion, tjmaul, and I apologize for not explaining throughly the main concept of the game, which is a very simple: one of those waterful ring toss games

    upload_2021-5-2_15-5-13.jpeg
    Because of that, I need the ring to be hollow in the middle, so the user can put it through the (stick?, sorry, don´t know the right word for that component of the game).
     
  10. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    467
    That's awesome! I loved those! I hope my suggestions helps to solve your problem, but if I recall correctly, the rings don't go through incredibly strong forces and don't bump into each other with huge velocity deltas, so penetration should not be an issue. Any chance the rings are only some millimeters in size? I advise their size should be about the size of the default cube (1m) and their weight should scale accordingly. The physics engines parameters are optimized for life sized moving objects like humans, cars, boxes, trucks etc.

    What just came into my mind are the water physics behind that. In case you haven't considered that, this is a very nice application for a simple 2d fluid simulation:
    http://haxiomic.github.io/GPU-Fluid-Experiments/html5/
    http://developer.download.nvidia.com/books/HTML/gpugems/gpugems_ch38.html
     
    abermann_O likes this.
  11. abermann_O

    abermann_O

    Joined:
    Aug 16, 2018
    Posts:
    42
    Thanks again, timaul! I´ll let you know when I publish the first Alpha, in case you want to be part of it and give me your valuable advice! I like your suggestion , and I didn´t take into consideration any scene size regarding to objects.... I wonder if that is the problem, and because of what you wrote, it may be. I´ll check it out and, if needed (sigh) rebuild the entire thing, but I prefer to do that that face intercollision, which in a game like this, is 100% unacceptable, itr just can´t happen.
    So once I rebuild the scene with the right proportions, I´ll be back to let you know how it works!
     
  12. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    467
    Ha, nice! Maybe finally in somebodies credits!

    Depending on your setup it might be enough to move all objects of your scene into another root game object and scale that.
     
    abermann_O likes this.
  13. abermann_O

    abermann_O

    Joined:
    Aug 16, 2018
    Posts:
    42
    Excelent idea! I´ll try that first