Collider points in Rigidbody.SweepTest

Hi

I am trying to understand - Rigidbody.SweepTest Unity - Scripting API: Rigidbody.SweepTest

The doc says “This is similar to doing a Physics.Raycast for all points contained in any of a Rigidbody’s colliders”, " this function only works when a primitive collider type (sphere, cube or capsule) or a convex mesh is attached to the rigidbody"

What does all points refer to here? Is it all vertices of the collider?

A SweepTest casts all the primite/convex colliders attached to the body, and gives you a result. The “all points” part can be misleading and confussing, maybe because the documentation is old (?).

Btw, this is what SweepTest does:
8481026--1127570--SweepTest final2.gif
Hierarchy

  • Body (Rigidbody, no colliders)
    —> Shere (SphereCollider)
    —> Cylinder (MeshCollider with convex enabled)

The orange shapes “belong” to the body (Rigidbody).
The yellow box (BoxCollider) is the obstacle.

I’m applying a SweepTest using the “Body” Rigidbody. The cast direction is Vector3.right.

By performing a SweepTest, two casts (in this case) are performed at the same time, one for each shape.
When the shape of a particular cast starts inside the obstacle (overlap), that obstacle gets ignored. This is why the hit point changes when i make the entire body move from left to right. Sometimes the cylinder is the one detecting the obstacle, sometimes it is the sphere.

I guess the “Physics.Raycast for all points” part tried to justify this behaviour in a way.

Thanks for the detailed explanation. I hope the documentation gets updated.