I have a script that its simply an AI with waypoint system that goes from 1 to other waypoint
heres the code:
var waypoint : Transform[];
var speed : float = 10.0;
var rotateSpeed : float = 1.0;
var loop : boolean = true;
var currentWaypoint : int;
var target : Transform;
function Awake(){
waypoint[0] = transform;
}
function Update(){
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{
transform.Translate(moveDirection.normalized * speed * Time.smoothDeltaTime);
}
}
else{
if(loop){
currentWaypoint = 0;
}
else{
velocity = Vector3.zero;
}
}
rigidbody.velocity = velocity;
}
but i cant make the AI to rotate towards the next waypoint, so i can change the translate to something more realistic and smoother movement.
Can anyone tell me what i need to make it rotate to the next waypoint ![]()