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

Resolved OverlapCapsule does not find closest point

Discussion in 'Physics for ECS' started by CookieStealer2, Aug 30, 2021.

  1. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    Hi.

    I expected OverlapCapsuleCustom() to return distance hits relative to the line segment that is describing the capsule. This does not seem to be the case. Consider this case, where a capsule is overlapped an inclined plane:
    upload_2021-8-30_11-54-24.png
    What I'm getting is the red normal. But this hit is not the closest to the line segment. That would be the point where the line segment and the plane intersect (where the blue normal originates). I don't see why I would want the red one, so I thought it was a bug. Or am I just misunderstanding the use of OverlapCapsuleCustom()? If so, I think there should be an exposed method for doing a distance check from a line segment.
     
  2. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    862
    Is this really a bug? I was under the impression that you need to sort the returned items.
     
  3. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    A hit with distance 0 is not among the returned items.

    Edit: Actually distance is measured from the capsule surface, so all distances inside is negative. Still, no hit with a position in the center is among the returned items.
     
    Last edited: Aug 31, 2021
  4. MaxAbernethy

    MaxAbernethy

    Joined:
    Mar 16, 2019
    Posts:
    53
    I think the base of the red arrow is the correct point to return. The red arrow points in the direction that you would move the capsule to separate it from the plane in the minimum distance possible. The base of the red arrow is where the capsule and the plane would be touching when the distance reached zero. That is true no matter what the capsule radius is, even if it's zero so that the capsule is a line segment. The only thing that would change is distance.

    One way to get the position in the center would be to cast a ray from one endpoint of the capsule's segment to the other. Whether that makes sense or not depends on what you're trying to do though.
     
    CookieStealer2 likes this.
  5. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    Ok, I see your point. I guess what I really need is a CalculateDistance() that uses a line or line segment as input instead of a point.