Patrolling AI doesn't see player if it's standing still

I have a problem with my patrolling AI script (again). I’m going to use it in my topdown Pac-Man style stealth game.

So my current enemy has a large box collider trigger component and the following script attached to it. The script moves the enemy around through waypoints. It also checks if the player enters the trigger and uses linecasting to tell if there are walls or anything blocking the view.

var waypoint : Transform[];
var speed : float = 10;
var currentWaypoint : int = 0;
var loop : boolean = true;
var player : GameObject;
private var character : CharacterController;
private var inRange : boolean = false;

function Start ()
{
character = GetComponent(CharacterController);
}

function OnTriggerStay(CollisionInfo : Collider)
{
    if(CollisionInfo.gameObject.tag == "Player")
    {
	    inRange = true;
    }
}

function Update () 
{

    if(inRange == true)
    {
	    var hit : RaycastHit;

	    if(!Physics.Linecast(transform.position, player.transform.position,hit))
	    {
	
	    Debug.Log("I see you!");
	    }
	
    }


    if(currentWaypoint < waypoint.length)
    {
        var target : Vector3 = waypoint[currentWaypoint].position;
        target.y = transform.position.y; // keep waypoint at character's height
        var moveDirection : Vector3 = target - transform.position;
        if(moveDirection.magnitude < 1)
        {
            transform.position = target; // force character to waypoint position
            currentWaypoint++;
        }
        else
        {
            transform.LookAt(target);
            character.Move(moveDirection.normalized * speed * Time.deltaTime);
        }
    }
    else
    {
        if(loop)
        {
            currentWaypoint=0;
        }
    }
}

function OnTriggerExit (CollisionInfo : Collider) 
{
    if(CollisionInfo.gameObject.tag == "Player")
    {
        inRange = false;
    }
}

This works very fine, but if I move my player into the enemy’s patrolling route and stand still when it goes by, it doesn’t notice me at all. But it does if it walks straight at me (so that our CharacterControllers collide).

Why is this happening? And how could I fix this? All answers and suggestions are welcome. I have no idea!

Thanks in advance!

Give your enemy a RigidBody and set it to kinematic. Otherwise its own motion won’t invoke triggers.