I'm trying to create a raycast for my enemy so if the player is behind a wall, the enemy will not attack...this is what im currently using inside my update function:
var dist = lookAtTarget.position - transform.position;
var hit : RaycastHit;
if(Physics.Raycast(transform.position, dist,hit))
{
if(hit.collider.CompareTag("Player"))
{
Attack();
}
else
{
return false;
}
Debug.DrawLine (transform.position, hit.point);
}
The problem im having is that when i play the game, if the player is in range of the enemy but standing still, the enemy will not attack...but if i start moving, thats when the enemy starts to attack...All im trying to get accomplished is to have the enemy disengage when the player is either behind a wall or out of range with the use of raycast...I also tried using linecast and i was getting the same result...