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