Game Development Reference
In-Depth Information
//Get Direction from the current position of the character to
the next way point
//Make sure that the y position equal to the waypoint y position
var v3_currentPosition : Vector3 = new Vector3(_AI.position.x,
waypoints[int_nextIndex].position.y, _AI.position.z);
v3_direction = (waypoints[int_nextIndex].position - v3_
currentPosition).normalized;
return v3_direction;
}
6. Next, we will add two more funcions to check the direcion from the enemy to
the player, and check to see whether the enemy is away from the target waypoint
at a speciic distance or not. Both of these funcions will give the enemy more
characterisics. Let's type both the funcions as follows:
//To get the direction from current position of the enemy to the
player
public function GetDirectionToPlayer ( _AI : Transform, _player :
Transform ) : Vector3 {
//Make sure that the y position equal to the waypoint y position
var v3_currentPosition : Vector3 = new Vector3(_AI.position.x,
waypoints[int_wayIndex].position.y, _AI.position.z);
var v3_playerPosition : Vector3 = new Vector3(_player.
position.x, waypoints[int_wayIndex].position.y, _player.
position.z);
v3_direction = (v3_playerPosition - v3_currentPosition).
normalized;
return v3_direction;
}
//Checking if the enemy is away from the target waypoint in the
specific distance or not
public function AwayFromWaypoint (_AI : Transform, _distance :
float) : boolean {
if (Vector3.Distance(_AI.position, waypoints[int_nextIndex].
position) >= _distance) {
return true;
} else {
return false;
}
}
 
Search WWH ::




Custom Search