void OnTriggerStay(Collider other)
{
// Check if the colliding object is santa
if (other.gameObject == santa && checkVision == true)
{
// Satisfies first condition. Must check if it satisfies other condition
// Initially default santaInSight to false
santaInSight = false;
// Determine if player is within field of view, use function called Angle. This takes in two vector3 and return angle between them
// Inputs:
// 1. Vector to Santa
// 2. Person's forward vector
// If this angle is less than half the field of view angle then santa is within the view
// Vector to santa
Vector3 direction = other.transform.position - transform.position;
// Angle between two values
float angle = Vector3.Angle(direction, transform.forward);
// Check if angle is less than half the field of view angle of person's field of vision
if (angle < fieldOfViewAngle * 0.5f)
{
// Check if there is obstruction between santa and person which will hide santa
RaycastHit hit;
rayPos2 = new Vector3(0, nav.height * 0.8f);
// Two raycasts of person.
// REASON: Prevent crouching from being not visible
// View of ray cast ground level transform.position
// Direction vector of ray cast is always normalized (0-1)
// Ray cast distance being the radius of the collider
if (Physics.Raycast(transform.position + rayPos1, direction.normalized, out hit, col.radius, layerMask))
{
if (hit.collider.gameObject == santa)
{
santaInSight = true;
}
}
if (Physics.Raycast(transform.position + rayPos2, direction.normalized, out hit, col.radius, layerMask))
{
if (hit.collider.gameObject == santa)
{
santaInSight = true;
}
}
}
}
}