Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Detecting + moving rigidbody on penetration of another collider

Discussion in 'Physics' started by FeastSC2, Nov 9, 2019 at 9:26 AM.

  1. FeastSC2


    Sep 30, 2016
    1) About penetration detection:
    How to detect when a rigibody is overlapping another collider BEFORE letting the Unity's default penetration algorithm handle the penetration itself? Unity physics will automatically push the rigidbody out of the collider that it's in but I would like to be able to decide in which direction the rigidbody will move when that occurs.

    Basically, I never want the rigidbody to be pushed downward (it goes through the terrain and falls forever).

    2) About moving the rigidbody:
    I found this method Physics.ComputePenetration, it's basically what I want but I would like to be able to set the direction myself.

    The reason why I want to know about this is:
    My game has a mechanic where walls appear and disappear which means that when the wall reappears, a rigidbody could have been placed where the wall is while he's hidden.
    The rigidbody would then automatically be pushed away, and it could be pushed downward like mentioned above, which means the rigidbody is forever lost.

    EDIT: About the penetration detection, I found a way: I could check that before the wall reappears if there is something that overlaps with it, I move it by a certain amount.
    Now, I still need to figure out part 2.
    Last edited: Nov 10, 2019 at 12:24 PM