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

Using Collider Bounds to Insure No Touching!

Discussion in 'Scripting' started by renman3000, Apr 24, 2019.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi there,
    I have a player, at rest.
    His collider, may be touching another collider (for example wall, or water).
    If this is the case, I want to move the player, so that his collider bounds, are outside of the object x, collider bounds.


    If I know the position of the player and object
    If I know the collider of the player and the object
    How can I best insure my adjusted player position, has the player collider bounds outside of the objects collider bounds?
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    In collision event there's collision normal. Project it on the floor and move player in opposite direction until collision exits.
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    And if you aren't using callbacks or casts, use ComputePenetration to get the normal and how much they penetrate by.
     
    palex-nx likes this.
  4. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    is this applicable to 2D? If not, which? Currently looking at defaultContactOffset()?
    Thanks