- Home /
SphereCastAll doesn't seem to be working
In desperation, I tried this:
RaycastHit[] hits = Physics.SphereCastAll(transform.position, 100000000f, transform.up, 100f);
and it STILL didn't work. It returned SOME hits but not all. My world just consists of a small room with some objects in it. Some with rigid bodies, some with only colliders. They are all in the default layer. This behavior just seems completely nonsensical. Can this be anything other than a bug in SphereCastAll?
Thanks
Answer by manzolo · Jul 11, 2013 at 05:31 PM
do you have any colliders set to triggers ? spherecast only detects colliders that are not set up as triggers, so any colliders that have is trigger option checked wont be detected by the spherecollider
hm have you tried setting the radius to 0.1 to see if you get a different result ?
Answer by robertbu · Jul 06, 2013 at 10:29 PM
If the object is already inside radius, it will not be detected. You can handle this in a couple of different ways. Image you wanted a radius of 10.0. You can do:
RaycastHit[] hits = Physics.SphereCastAll(transform.position-transform.up*10.0, 10.0f, transform.up, 100f).
Another possibility is to do a Physics.OverlapSphere()first, and then to add any new items found by call to Physics.SphereCastAll() with a radius the same size.
Thank you for your answer. There are two problems with that.
1) When I use radius 100000000f, I actually do get some 'hits'. Though that number seems to change, sometimes 2, or 5 or 6 hits. And I can assure you that I don't have any objects that far out.
2) Conceptually, OverlapSphere would be perfect for me. But in the documentation it says that it presently only checks for collisions with other objects' bounding boxes rather than the colliders themselves. That would be fine if there was some other physics query function to check for a collision between a given pair of colliders, but afaik there is no such function.
This seems crazy. All I want to do is check, when the user clicks, whether there is something within a certain radius of a given position (or ideally within an arbitrary shape). I would have thought that to be a very common usage?