Game Development Reference
In-Depth Information
distance : float ) : boolean {
var offset : Vector3 = position -
waypoints[_nextIndex].transform.position;
var length : float = offset.sqrMagnitude;
var sqrDistance : float = distance*distance;
if (length > sqrDistance) {
return true;
} else {
return false;
}
}
// C# user:
public bool AwayFromWaypoint ( Vector3 position,
float distance ) {
Vector3 offset = position -
waypoints[_nextIndex].transform.position;
float length = offset.sqrMagnitude;
float sqrDistance = distance*distance;
if (length > sqrDistance) {
return true;
} else {
return false;
}
}
5. Then, we need to add another function, which will basically return the direction
from our AI to the player. This function is to make our enemy follow the player to
make it more aggressive. Let's add the function after the AwayFromWaypo-
int() function as follows:
// Unity JavaScript user:
function GetDirectionToPlayer ( enemy : Vector3,
player : Vector3 ) : Vector3 {
var currentPosition : Vector3 = new
Vector3(enemy.x,
Search WWH ::




Custom Search