Hey!
Just like the name implies, i need some help scrpiting some “Ai”. Me and a few of my friends is creating a space shooter game, sort of like Star Fox, and we have the basic elements done, except for enemy behaviours.
What i want the enemy to do is basically this: When the player is in reach, the enemy will chase the player while firing. When the player is out of their reach, they return to their waypoint patrolling.
So, have you guys got any ideas? This is the waypoint code i use at the moment.
var waypoint : Transform[];
var speed : float = 20;
private var currentWaypoint : int;
var loop : boolean = true;
function Update(){
if(currentWaypoint < waypoint.length){
var target : Vector3 = waypoint[currentWaypoint].position;
var moveDirection : Vector3 = target - transform.position;
var velocity = rigidbody.velocity;
transform.LookAt(target);
if(moveDirection.magnitude < 1){
currentWaypoint++;
}
else {
velocity = moveDirection.normalized * speed;
}
}
else {
if (loop){
currentWaypoint=0;
}
else{
velocity = Vector3.zero;
}
}
rigidbody.velocity = velocity;
}