- Home /
Physics.SphereCastAll ignore objects in opposite direction?
Hi,
I'm using SphereCastAll to detect some objects in an explosion radius. It works fine for objects sitting in the cast direction, but objects on the opposite of the cast direction appear to be ignore, even when they do intersect with the cast sphere. Anyone seeing this as well? Is this expected?
Answer by Owen-Reynolds · Feb 02, 2012 at 08:29 PM
A sphereCast is meant to go in a direction, to check if a sphere-shaped object can move along that path. The "ALL" just means it gives info about everyone it hit, instead of the first thing.
For an explosion, use Physics.OverlapSphere
. There (is/was) a tiny bug that it can get some things a tiny bit too far away, but for an explosion, you're probably checking Mathf.magnitude(transform.position - C[i].transform.position)
anyway, for amount of damage.
Just like to add: Yes, it is the expected behaviour ;)
collisions only happens when you enter a collision surface. Ray- / Sphere- / Capsule- casts from inside a collider can never hit the collider. Only when the trace hit the positive collision surface of a collider.
Note: This function will return false if you cast a ray from inside a sphere to the outside; this in an intended behaviour.
Ah, yes. I was going to suggest that a large, 0.01 meter SphereCast would do the same thing as an OverlapSphere. But of course it won't -- it would only tell you about new things it hit as it moved.