Hi,
I have an enemy with line and angle of sight. However when I check if it can directly see the player, Raycast never hits the player. To check if it works, I put some other game objects like cubes, and Raycast reports them.
Example:
As you can see, Debug.DrawRay goes through player but RayCast info only gives Plane as the info.
This is the code I am using.
Vector3 direction = other.transform.position - transform.position;
float angle = Vector3.Angle( direction, transform.forward);
if( angle < fieldOfViewAngle * 0.5f){
RaycastHit hit;
if( Physics.Raycast( transform.position + transform.up, direction.normalized, out hit, col.radius)){
Debug.Log("Name: " + hit.collider.gameObject.name + " Tag: " + hit.collider.gameObject.tag);
//if( hit.collider.gameObject == player){
if( hit.collider.gameObject.tag == "Player"){
playerInSight = true;
Debug.Log("Enemy sees Player");
lastPlayerSighting.position = player.transform.position;
//personalLastSighting = player.transform.position;
}
}
}