Game Development Reference
In-Depth Information
As we can see from the preceding diagram, the enemy will run towards the player if the
distance between the player and the enemy is higher than
shotRange
but lower than or
equal to
playerRange
. Also, the enemy will shoot the player if the distance between
him and the player is in
shotRange
.
We also use
Physics.Raycast()
to check if there is a wall in front of the enemy or
not. If there is, we check the different height of the current object
y
position to the maxim-
um of wall height by using
hit.collider.bounds.max.y - hit.point.y;
and make sure that the height is lower than 2.5. Then, our enemy can jump over.