Game Development Reference
In-Depth Information
In the Run() funcion, we used the if ((Vector3.Distance(transform.position,
player.position) <= (getPlayerRange+shotRange)) && ((Vector3.
Distance(transform.position, player.position) > shotRange))) {}
statement to check for the distance between the enemy and the player, which we can see
from the following diagram:
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 the shotRange but lower than or
equal to the getPlayerRange . And the enemy will shoot the player if the distance between
him and the player is in the shotRange .
We also use both Physics.CapsuleCast() and Physics.RayCast() to check for the
wall in front of the enemy.
Classified Intel
In this step, we have used both the Physics.CapsuleCast() and Physics.RayCast()
funcions. Both funcions are very useful when one wants to check if there is anything
blocking the enemy movement direcion or the rocket bullet direcion.
We use Physics.CapsuleCast() for our Jump() funcion because we want to check the
area in front of the enemy and whether the capsule hits the wall or not. We also check the
CollisionFlag.Sides for when the side of enemy collides with the wall as we use in the
Jump() funcion, as shown in the following script:
if ((Physics.CapsuleCast (p1, p2, 0.1, _direction, hit)) && (c_
collisionFlags & CollisionFlags.Sides)) {
 
Search WWH ::




Custom Search