- Home /
How can I test if there is a collision near my rigidbody?
I would like to be able to probe the space around my character to determine if there is any environment colliders nearby.
For example: If the character is less that 1 unit above the ground, I would like to be able to tell this, even though they aren't quite touching.
An obvious method would be to do a raycast down from their position. If the ray hits, then there is something below them.
However, what if there is a gap in the ground directly below their center? Or they are hanging over a cliff or on a spire? In these cases, the ray would (incorrectly) show that there is nothing beneath them, even though they are about to collide with the ground.
Is there such a thing as a 'shape cast'? So I could, say, project a sphere out from the bottom of the player and get information about whether or not it will collide with something?
Answer by syclamoth · Sep 18, 2011 at 04:47 AM
Have you looked at Physics.SphereCast? It does exactly what you want here. Honestly you should just read through the documentation a bit- there's lots of useful stuff in there!
I missed it the first time through the docs, and then found it after posting the question. Figured I'd leave the question up though for future generations. ;)