I’ve been working on a script where if the player is in sight of an enemy, they will shoot, but for some reason it never detects. what am I doing wrong? the capsule I’m using as a player is flagged as such
currentdist = Vector3.Distance(transform.position, player.transform.position);
RaycastHit hit;
var rayDirection = player.transform.position - transform.position;
positioning = new Vector3(this.transform.position.x, this.transform.position.y + 1, this.transform.position.z);
if (currentdist < safedist && Physics.Raycast(positioning, rayDirection, out hit) && (hit.collider.tag == "Player"))
{
nav.destination = player.transform.position;
Debug.DrawRay(transform.position, rayDirection * 1000, Color.red);
Debug.Log("Seeyou!");
shootatplayer();
}
else
{
Debug.DrawRay(transform.position, rayDirection * 1000, Color.white);
nav.destination = points[destPoint].position;
if (!nav.pathPending && nav.remainingDistance < 0.5f)
{
GoToNextPoint();
}
}