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");
}
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.