Game Development Reference
In-Depth Information
Vector3 leg = transform.position +
_characterController.center + up;
float distance = _characterController.radius *
2;
if (Physics.Raycast(leg, direction, out hit,
distance)) {
if (hit.transform.CompareTag("Wall")) {
float height = hit.collider.bounds.max.y -
hit.point.y;
if (height <= 2.5f) {
return true;
}
}
}
return false;
}
◦ Then, we will check the distance between the player and the enemy to see
if the distance is higher than shotRange and lower than shotRange
+ playerRange . So, let's add it as follows:
// Unity JavaScript user:
function Run () : boolean {
var distanceToPlayer : float =
(targetLookat.position -
transform.position).sqrMagnitude;
var runDistance : float =
(playerRange+shotRange)*(playerRange+shotRange);
var shotDistance : float = shotRange*shotRange;
if ((distanceToPlayer <= runDistance) &&
(distanceToPlayer > shotDistance)) {
return true;
}
return false;
}
// C# user:
Search WWH ::




Custom Search