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?