Game Development Reference
In-Depth Information
Your model now has all the necessary components needed to work with our AI script.
Scripting the animations
To script our animations, we will take a simple approach to it. There won't be a lot of
code to deal with, but we will spread it out in various areas of our script where we
need to play the animations. In the Idle function, add this line of code:
animation.Play("idle");
This simple line of code will play the idle animation. We use animation to access
the model's animation component, and then use the Play function of that compon-
ent to play the animation. The Play function can take the name of the animation to
call the correct animation to be played; for this one, we call the idle animation.
In the SearchForTarget function, add this line of code to the script:
animation.Play("run");
We access the same function of the animation component and call the run anima-
tion to play here. Add the same line of code to the Patrol function as well, since we
will want to use that animation for that function too.
In the RangedAttack and MeleeAttack functions, add this code:
animation.Play("attack");
Here, we call the attack animation. If we had a separate animation for ranged at-
tacks, we would use that instead, but since we don't, we will utilize the same anima-
tion for both attack types. With this, we finished coding the animations into our AI. It
will now play those animations when they are called during gameplay.
Search WWH ::




Custom Search