So I want a raycast to use compareTag but it doesn’t seem to work, Also the player is tagged correctly.
Thanks in advance.
void DetectionF(float distanceToTarget)
{
float angle = Vector2.Angle(vision, target.position);
if (lastAngle!=angle)
Debug.Log("Angle: " + angle);
lastAngle = angle;
Debug.DrawLine(transform.position, target.position, Color.red, 0.2f);
if (70f< angle && angle<140f)
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, target.position, distanceToTarget);
//This right here is where the problem lays
if (hit.collider.gameObject.CompareTag("Player"))
{
player.detected = true;
CancelInvoke("Undetect");
}
}
}