- Home /
Why isn't my Sphere Cast hitting anything?
Heya, I am trying to use a Sphere cast with a direction of 0 to draw a sphere around my character controller in order to detect if anything at all is within a certain radius.
But my Sphere cast isn't working, or at least not picking anything up, and Unity doesn't seem to have any visualization options for the sphere cast for some reason, so I'm totally bind as to what it is doing, or what might be going wrong.
here is my code
RaycastHit Overlap;
if (Physics.SphereCast(this.transform.position, 500, Vector3.zero, out Overlap))
{
Debug.Log("You're in my Personal Space");
}
Answer by WroughtINT · Jan 26, 2021 at 05:37 PM
Well, turns out it's just a strange quirk with Unity's Sphere Cast system.
This method ONLY works if the Distance isn't Zero. The initial overlapping region of the sphere is ignored, the sphere cast only registers and entry if the edge moves towards something AND overlaps, it will ignore the object if it starts overlapped with it.
I don't know why it acts this way, but it is as it is. (Proper Visual debugging tools would have been helpful for this, since constructing debugs from my own Gizmos failed to highlight this issue)
A better alternative for my situation was instead to use a Physics.OverlapSphere. then ~LayerMask out my player, and then check if the .Length of the Overlap results is =0
That system checks if no things are overlapping the region.
Your answer
Follow this Question
Related Questions
Physics.SphereCastAll ignore objects in opposite direction? 1 Answer
Getting points within a radius to place burn decals from an explosion 2 Answers
Unity C# Bomb Radius Issue 0 Answers
How to find the velocity of a gameobject that has be hit by the spherecast ? 1 Answer
lock on enemy 3d spaceshooter 1 Answer