Follow Player Via Waypoints

Hey guys,
I was looking for a way to get the enemy to just move towards the player via the waypoints.
This is the script i have so far:
var waypoint : Transform;
static var speed : float = 1;
private var currentWaypoint : int;
var self : GameObject;

    function Update () 
    {
        self.transform.rotation = Quaternion.LookRotation(rigidbody.velocity);
        if(currentWaypoint < waypoint.length)
        {
            var target : Vector3 = waypoint[currentWaypoint].position;
            var moveDirection : Vector3 = target - transform.position;
            var velocity = rigidbody.velocity;
 
            if(moveDirection.magnitude < 1)
            {
                currentWaypoint++;
            }
            else
            {
                velocity = moveDirection.normalized*speed;
            }
        }
 
        rigidbody.velocity = velocity;
    }

If anyone can help me or provide me with an alternate method i would be extremely greatful,
Thanks :smiley:

Try applying some force to your rigidbody in the direction you want it to go instead of velocity. My understanding is that it isn’t recommended to modify velocity directly.

rigidbody.AddForce(velocity * speed);

If your enemies are more like people, it may be more appropriate to use a CharacterController for your enemy and move it that way. But if your enemies are more, well, rigid, like a vehicle or something, than RigidBody is probably the right one to use.

And depending on how complex your environment is, you could use other techniques to have the enemy find the player. Have you looked into A* and other path finding techniques? Unity provides a NavMesh (I haven’t used it yet), but that could be useful - Pro only I think.