Game Development Reference
In-Depth Information
Then, we will check the distance between the player and the enemy to see
if the distance is higher than the shotRange and inside the shotRange +
getPlayerRange . So, let's add it as follows:
//Make the enemy run when the player hit certain radius
which is between the shotRange and getPlayerRange
public function Run () : boolean {
//Checking for Running
if ((Vector3.Distance(transform.position, player.
position) <= (getPlayerRange+shotRange)) && ((Vector3.
Distance(transform.position, player.position) > shotRange)))
{
b_isRun = true;
} else {
b_isRun = false;
}
return b_isRun;
}
In the last funcion, to control the enemy behavior, we will make our enemy
walk and stop for a certain amount of ime:
//Calculate the time that let enemy walk and stop for the
certain time
public function IsThinking() : boolean {
//Get the time when enemy stop walking
if (b_isStop) {
var f_time : float = thinkingTime;
} else {
//Get the time when enemy is walking
f_time = walkingTime;
}
if (Time.time >= (f_lastTime + f_time)) {
if (b_isStop) {
b_isStop = false;
} else {
b_isStop = true;
}
f_lastTime = Time.time;
}
return b_isStop;
}
Now we are done with all the funcions that give personality to our enemy.
 
Search WWH ::




Custom Search