I'm using the following waypoint system but I am unable to get the characters to face the direction the are moving in. Can anyone be of assistance in telling me how to do so?
var Waypoint : Transform[];
var speed : int = 20;
private var currentWP : int;
var loop : boolean = true;
function Update() {
if(currentWP < Waypoint.length){
var target = Waypoint[currentWP].position;
var moveDirection : Vector3 = target - transform.position;
var velocity = rigidbody.velocity;
if (moveDirection.magnitude < 1){
currentWP++;
}
else {
velocity = moveDirection.normalized * speed;
}
}
else{
if(loop){
currentWP=0;
}
else{
velocity = Vector3.zero;
}
}
rigidbody.velocity = velocity;
}
@script RequireComponent(Rigidbody)