Game Development Reference
In-Depth Information
Now we know that our problem comes from something inside the AIController
script, which should be the funcion that we call while the AI is moving. So, open the
AIController script, which is located in the Chapter7/Scripts folder in the Project
view, as shown in the following screenshot:
Now, double-click it, open the script and take a look at the Update() funcion, which is the
core funcion to control our AI.
Engage Thrusters
Inside the Update() funcion, we know that the problem arises only when the character
moves (which will be when the AI is not stopping or aiming).
Let's take a look inside if (!b_isAiming) {……} ; we will see nothing different from the
CharacterControl script, which we already used to control our character in Project 4 , The
Hero/Heroine Part II - Animaion and Controls , so it shouldn't be a problem, right? However,
one part of the script that we have changed to make our AI jump instead of geing the Input
key is the Jump(_direction : Vector3) funcion.
In the Jump(_direction : Vector3) funcion, you will see that we have used Physics.
CapsuleCast to check for the AI to jump if the step is in front of it. As we discussed in the
last chapter, Physics.CapsuleCast will cast the capsule collision in the given direcion
(which is the _direction that gets passed from Jump funcion) to check if the capsule
hit something.
Now, just think about it—do we really need to cast the capsule checking for the step and
make the AI jump? Can't we cast only one ray to check for it?
The answer is "Yes. We can do it".
 
Search WWH ::




Custom Search