Game Development Reference
In-Depth Information
The waypoint script will not work properly if we put the waypoint where
the enemy can't walk through, which means that our enemy should be able
to walk through and touch each waypoint (hit the green wire sphere area of
each waypoint, as shown in the preceding screenshot). Otherwise, the enemy
won't be able to move to the next waypoint.
We can also adjust the radius (you will see the green wire sphere change
its size) in the Waypoints script, which will make our enemy start turning
to the next waypoint faster or slower. However, we should be careful while
adjusing the radius. If we set it too low, the character might not hit it and not
turn to the next waypoint. So, the minimum radius should be 1.0.
In the next step, we will coninue by creaing the AIController script to make our enemy
walk through each waypoint.
Objective Complete - Mini Debriefing
What we have done here is created the waypoint, which basically controls the movement of
the enemy. We started by creaing the Waypoints script, which gets the transform posiion
of the game object and its children by using gameObject.GetComponentsInChildren.<
Transform>() .
Then, we added the getDirection() funcion, which checked the distance between the
enemy posiion and waypoint posiion, as shown in the following diagram:
We can see from the preceding diagram that if the distance between the enemy and
the waypoint posiion is smaller than the radius of the waypoint, it will trigger the
waypoint to change the next waypoint index, which will also change the movement
direcion of the enemy.
 
Search WWH ::




Custom Search