Game Development Reference
In-Depth Information
return false;
}
◦ Secondly, we will create the Jump() function to make our enemy
smarter by using the Physics.Raycast() function, but this time, we
will also check the wall height. If the wall is higher than the limited
height, our character will not jump. If not, it will jump over and continue
walking towards its direction, as in the following code:
// Unity JavaScript user:
function Jump ( direction : Vector3 ) : boolean {
var hit : RaycastHit;
var up : Vector3 = Vector3.up *
(-_characterController.height*0.5f);
var leg : Vector3 = transform.position +
_characterController.center + up;
var distance : float =
_characterController.radius * 2;
if (Physics.Raycast(leg, direction, hit,
distance)) {
if (hit.transform.CompareTag("Wall")) {
var height : float =
hit.collider.bounds.max.y - hit.point.y;
if (height <= 2.5f) {
return true;
}
}
}
return false;
}
// C# user:
public bool Jump ( Vector3 direction ) {
RaycastHit hit;
Vector3 up = Vector3.up *
(-_characterController.height*0.5f);
Search WWH ::




Custom Search