- Home /
Question by
psuess · Feb 27 at 11:55 PM ·
raycastspherecast
Why won't my spherecast work?
I want to make a spherecast that detects a type of object. But for some reason this is not working.
{
public float scannerRadius = 2;
private Vector3 origin = new Vector3(0, 0, 0);
// Update is called once per frame
void Update()
{
Scan();
}
void Scan()
{
Ray scannerRay = new Ray(origin, Vector3.back);
RaycastHit scannerHitInfo;
if (Physics.SphereCast(scannerRay, scannerRadius, out scannerHitInfo) && scannerHitInfo.collider.gameObject.CompareTag("MoveableObject"))
{
Debug.Log("scanning object");
}
}
}
When I do a raycast in the exact same way, that works fine and the message is displayed. But I need a spherecast for this to function properly, because I want a larger radius:
{
public float scannerRadius = 2;
private Vector3 origin = new Vector3(0, 0, 0);
// Update is called once per frame
void Update()
{
Scan();
}
void Scan()
{
Ray scannerRay = new Ray(origin, Vector3.back);
RaycastHit scannerHitInfo;
if (Physics.Raycast(scannerRay, out scannerHitInfo) && scannerHitInfo.collider.gameObject.CompareTag("MoveableObject"))
{
Debug.Log("scanning object");
}
}
}
So, I'm wondering why the raycast works fine but the spherecast doesn't? I've tried including the range in the parameter as well, but that doesn't make a difference.
Comment
Your answer
Follow this Question
Related Questions
Can Raycast get multiple points from the same collider? 1 Answer
How do you perform a stationary SphereCastAll? 1 Answer
Car AI help 0 Answers