Physics.OverlapCapsule problem

Really simple. I have a flat plane at 0, 0, 0. Naturally there is absolutely no y dimension to speak of in this plane. For whatever reason, though, the line of code

Collider[] colliders = Physics.OverlapCapsule(Vector3.up * 0.99f, Vector3.up * 5, 1)

returns the collider for the terrain despite the fact that the capsule is suppose to be 0.99 units above the plane and therefore not touching it at all. What’s really baffling, though, is that the line of code works just fine when the bottom of the capsule is Vector3.up * 1f, so why is there only a problem if the y value of the bottom is below 1?

The radius of your capsule is 1. That means the round ends of your capsule extend in a hemisphere with radius 1 unit around the two points of the capsule. If the bottom point is at .99 and it has radius 1, naturally it will reach the ground.

Think of the capsule as two spheres with the centers at the points you gave and radius you gave, and then there’s just a cylinder that stretches between them.

1 Like

So I’m to assume then that the true bottom of the capsule is Bottom + Vector3.down * radius?

No it’s bottom + ((bottom - top).normalized * radius) because the capsule is not guaranteed to be aligned with the y axis.

Let’s say it is guaranteed to be aligned with the y axis. Would it be Bottom + Vector3.down * radius in that case?

Yes, because in that case, (bottom - top).normalized is equivalent to Vector3.down

it also kinda depends what you mean by “bottom”. If you mean “lowest point of the capsule in the game world”, then it’s always Bottom + Vector3.down * radius, because the tips of the capsule are hemispheres. If you mean the furthest point on the capsule from the “Top” reference point, then it’s the other formula I gave.

In this case it’s definitely the lowest point of the capsule in the game world.