Hi,
I have a spotlight that rotates around its X axis, sort of a Security light that the player has to avoid.
I’m trying to detect when the player touches the light using physics.SphereCast, but it’s a trouble maker-
I can’t seem to get the exact radius to fit perfectly in the light, it either detects the player a few dozen pixels before it reaches him, or it doesn’t detect him at all…
this is the script I attached to the rotating light :
public class LightPatrol : MonoBehaviour {
void Update() {
RaycastHit hit=new RaycastHit();
if (Physics.SphereCast(transform.position, 4.0f, transform.forward,out hit, 1))
{
if(hit.collider.gameObject.tag == "Player") {
animation.Stop("LightFlip");
}
}
}
}
Is there a better way of doing this?