Search Unity

Physics.ComputePenetration simple question

Discussion in 'Physics' started by AnKOu, Jun 20, 2019.

  1. AnKOu

    AnKOu

    Joined:
    Aug 30, 2013
    Posts:
    123
    Today, I use Physics.ComputePenetration to keep a collider outside another one.

    My problem is that the function return the direction for which the distance is the lowest. It cause me problem as I would like to keep the penetration collider on the same side it is when initialy outside.
    Like a wall, to prevent object to go through it.

    I tried to find a algorithm which would do the same as ComputePenetration but would take another argument that would be the direction we want.

    In short is it (easilly) possible to get the distance along an axis for which the two colliders are separated ?
     
  2. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    I think you would look into Physics.SweetTest or CapsuleCast /other colliderCast for that issue. If they are bound to one plane you could maybe solve it with some dot product + adjust distance and then do the penetrate check as well.
     
  3. Jarkko129

    Jarkko129

    Joined:
    Nov 15, 2019
    Posts:
    2
    My solution was to spawn an 2.0f, 2.0f, 1.0f scaled object to make an invisible wall and do the calculation with it instead of the initial collider. Just place the wall to the correct position before calculating