Game Development Reference
In-Depth Information
8. The next step is the Update() funcion, which will control all the movement and
animaion of our enemy. So, let's type it as follows:
public function Update() : void {
if (StaticVars.b_isGameOver == false) {
var v3_rocketDirection : Vector3 = (player.position -
transform.position).normalized;
//Checking if the enemy position is away from the waypoint in
the certain distance,
//Make the enemy stop running, shooting, and walk back to the
target waypoint
if (wayPoint.AwayFromWaypoint(transform, waypointDistance)) {
b_isAiming = false;
b_isRun = false;
} else {
//Checking if the enemy is not aiming - check for running
if (!Shoot(v3_rocketDirection)) {
//Checking if the ai is run or not aiming
Run();
}
}
9. Coninue to add the following script in the Update() funcion, which will check
when the enemy isn't aiming, and then we will check for b_isRun to see if the
enemy is running or not:
if (!b_isAiming) {
//If the ai is running don't make it think
//Get the direction
if (b_isRun) {
var v3_targetDirection : Vector3 = wayPoint.
GetDirectionToPlayer(transform, player); //Move Direct to the
player
} else {
if (thinkingTime > 0) {
if (!IsThinking()) {
v3_targetDirection = wayPoint.GetDirection(transform);
//Use random Direction
} else {
v3_targetDirection = Vector3.zero;
}
} else {
v3_targetDirection = wayPoint.GetDirection(transform);
//Use random Direction
}
}
 
Search WWH ::




Custom Search