Why does Collider2D.Cast exist, but not Collider.Cast?

This seems obvious to me, so maybe I am missing something?

I’d like to do a physics cast after a trigger hit to get contact data. Ideally, I would not need to hard code in the type(s) of cast when the trigger collider could be… anything.

This exists for Collider2D: Unity - Scripting API: Collider2D.Cast
However for some unspecified reason which also appears to be unknown to google, Collider’s (the 3D ones) do not have a similar method.

I suppose casting mesh colliders could be a performance pitfall, but I doubt PolygonCollider2D’s (which inherit Collider2D.Cast) are great either. I probably just want a sphere anyways but this is odd and annoying.

2 Likes

Because they are two different underlying systems (PhysX & Box2D) integrated separately by different teams. Whilst some things stay in sync not everything does and priorities are different.

4 Likes

There are some alternatives in 3D physics:

The Physics class includes cast methods for the primitive colliders: BoxCast, SphereCast, CapsuleCast

If your collider has a Rigidbody then you may use SweepTest. This is a cast using all the colliders in the Rigidbody.

2 Likes