Search Unity

Using the physics package to find the closest valid arrangement of colliders?

Discussion in 'Physics for ECS' started by Bas-Smit, Feb 10, 2021.

  1. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    My game is basically a few capsules inside a box, being moved around by changing their velocities then updating the physics simulation. Occasionally however I need to rotate and or move a capsule instantly. Placing this capsule so it does not intersect with the box is easy, but any number of capsules may intersect when the capsule is rotated. I need to calculate positions and orientations for all capsules so none intersect, and the total change from their original positions and orientations is minimized. Is there anything in the physics package to help with something like this?
     
  2. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    Is it good enough to approximate capsules with their AABBs? If yes, that would speed up (and simplify) overlap tests greatly.
     
  3. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    I think that your problem is one of those NP problems.
    This is going to be hard.
     
  4. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    I should have said a close arrangement :), I'm thinking something like: detect a capsule capsule intersection, move both capsules half the distance required to not intersect, repeat until no intersections are found. Before checking capsule capsule collisions check for capsule box collisions and move the capsule the full distance required as the box is static. I would be nice to also consider rotation to rearrange the colliders though
     
    Last edited: Feb 11, 2021