How do I get my emeny AI to detect if he sees a player, or one of the good AI? (C#)

I’m having a problem with getting my Enemy AI to detect my player, or any of the good AI.

I’m trying to make it so that if the enemy AI sees the player, or one of the good AI, it goes after it.

I can’t get it working, though. Even if I stand right in front of the enemy, he doesn’t see me, and doesn’t move.

Here’s my code:

		RaycastHit hit;
			Vector3 directionOfLine = myTransform.TransformDirection(Vector3.forward);
			Debug.DrawRay((myTransform.position + (Vector3.up * 6) + (Vector3.forward * 4)), directionOfLine * range, Color.red);
			if (Physics.Raycast((myTransform.position + (Vector3.up * 6) + (Vector3.forward * 4)), directionOfLine, out hit, range))
			{
				if (hit.rigidbody.tag == "Player" || hit.rigidbody.tag == "Rossi Comrade")
				{
					target = hit.transform;
					targetInSight = true;
				}
			}

(The model origin is on their feet, so it’s got “Vector3.Up.” added to it to put the line origin at the head)

What am I doing wrong?

// Parent an empty gameobject called eye and
// place it at the eye of the AI object with the z axis facing forward
public Gameobject eye;
public float viewDistance = 10f;
public RaycastHit hitInfo;
Physics.Linecast( eye.transform.position, eye.transform.position + (eye.transform.forward * viewDistance), out hitInfo );
// Test out by making the rigidbody isKinametic = true and manually dragging the AI to front of player/ good AI
Debug.Log(hit.collider.tag);
Code not tested but hope it helps.

Are layers configured properly? Can enemy and player see each other? Maybe layer is ignoring raycasts.

I got it working, it turns out the player doesn’t have a rigidbody, but a Chaacter controlelr, so I changed it to hit.collider, and it worked!