Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question If a point is inside a collider, how do I find how high the point must go to get out of the collider

Discussion in 'Physics' started by kooltyme1, Dec 6, 2022.

  1. kooltyme1

    kooltyme1

    Joined:
    Apr 13, 2022
    Posts:
    10

    Could I use raycasts, and somehow set the mask as empty space?
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,598
    Calculate another point that's definitely outside, and raycast toward your point. If it hits your collider, your point is inside. There are edge cases for concave colliders but that solves for most uses. The basic geometry colliders can also return the closest point on the surface of the collider. https://docs.unity3d.com/ScriptReference/Collider.ClosestPoint.html
     
    Edy and kooltyme1 like this.
  3. kooltyme1

    kooltyme1

    Joined:
    Apr 13, 2022
    Posts:
    10
    That'll work