Game Development Reference
In-Depth Information
waypoints[_wayIndex].transform.position.y, enemy.z);
var playerPosition : Vector3 = new
Vector3(player.x,
waypoints[_wayIndex].transform.position.y, player.z);
_direction = (playerPosition -
currentPosition).normalized;
return _direction;
}
// C# user:
public Vector3 GetDirectionToPlayer ( Vector3 enemy,
Vector3 player ) {
Vector3 currentPosition = new Vector3(enemy.x,
waypoints[_wayIndex].transform.position.y, enemy.z);
Vector3 playerPosition = new Vector3(player.x,
waypoints[_wayIndex].transform.position.y, player.z);
_direction = (playerPosition -
currentPosition).normalized;
return _direction;
}
6. Next, we will add the core function, which will calculate and return the enemy's
direction related to the player's position. We will also set the way the enemy will
be moved through the waypoint either by an order or randomness. So, type the
following code:
// Unity JavaScript user:
function GetDirection (myTransform : Transform) :
Vector3
{
var offset : Vector3 = myTransform.position -
waypoints[_nextIndex].transform.position;
var length : float = offset.sqrMagnitude;
var sqrDistance : float = radius*radius;
if (length <= sqrDistance) {
if (!_isHitRadius) {
Search WWH ::




Custom Search