Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  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:
    1,860
    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