No Physics.CheckBox(). What do you do instead?

Hello!

So I notice there’s Physics.CheckSphere and Physics.CheckCapsule, but no Physics.CheckBox. I’m about to make a helper script that uses raycasts to try and approximate the same thing.

The use case: I want to see if I can increase the size of a BoxCollider and still have the collider fit.

What do you guys use?

Just use a trigger BoxCollider, set its size and position to what you want, then use an OnCollisionEnter message to get the colliders within it.

However, that might take an extra frame to register, I’m unsure. You might be able to use raycasts, but you’d have to do a lot to get a decent resolution.

Unfortunately, creating a box collider means I have to instantiate it, or used a pooled one. Then I update the box collider’s size and position, then wait for a FixedUpdate() to run before I can finally have my answer.

With CheckSphere() and CheckCapsule(), I know the answer immediately and can take action on the next line of code.

I made a custom CheckBox() function that raycasts around a cube, but it will still miss small colliders or large colliders that completely contain the box I want to check. It works for now, but not the ideal solution.

1 Like

You could use a hybrid solution: CheckCapsule with the same dimensions as the box, then raycasts for the corners. That’ll get any colliders that completely enclose it as well.

1 Like

That’s a good idea! I mean there are still corner cases (hahahahahaa) where it’ll miss a collider, but definitely better than raycasts alone.