Adding transitions

Next, we need to set the condition for each transition. The condition decides when a zombie transitions from one state to another, such as from walking to attacking. For our game, we have seven transitions, as shown in Table 5.3. A zombie's starting state is walking and it transitions to either attacking or dying, depending on whether it collides with the player or the Raycaster. If it collides with the Raycaster, the transition is one of the three death animations. If it collides with the player, then it plays an attack before switching to a death:

  1. Select a transition arrow and review its settings in the Inspector window. Note that at the bottom of the window the Condition panel is empty. Add a condition to each transition by clicking the + button and complete the fields by using the following chart. Additionally, be sure to uncheck the Has Exit Time checkbox for each transition. Table 5.3 outlines the Attack, Death, and DeathAnimationIndex values for each transition:

Transition

Has Exit Time

Conditions

Walk->Attack

False

Attack is True

Walk->Fallback

Death is True
DeathAnimationIndex Equals 0

Walk->FallLeft

Death is True
DeathAnimationIndex Equals 1

Walk->FallRight

Death is True
DeathAnimationIndex Equals 2

Attack->Fallback

Death is True
DeathAnimationIndex Equals 0

Attack->FallLeft

Death is True
DeathAnimationIndex Equals 1

Attack->FallRight

Death is True
DeathAnimationIndex Equals 2

Table 5.3: Condition settings for each transition

Thankfully, the Zombie asset came with these animations. They'll work perfectly for our project with one minor tweak. The current walk cycle animates for a single stride. However, to have our undead creatures move naturally toward the player, we'll need a full stride that repeats the entire duration of the movement.

  1. Double-click the Walk state in the Animator window. This will open the object in the Inspector panel.
  2. Choose the Animation button (see Figure 5.10) and scroll down to the walk animation section. Convert the animation to a walk cycle by checking the Loop Time option.
  1. Hit the Apply button to save the change:
>
Figure 5.10: Looping the walk animation

Now that the ZombieAnimator has been created, we can assign the state machine to the ZombiePrefab.

  1. Select the ZombiePrefab and note that the Controller field in the Inspector panel is set the None (Runtime Animator Controller).
  2. Click the target selector on the Controller field and select the ZombieAnimator from the Select Runtime Animator Controller window.
  3. Save the ShootingRange scene and the project.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.102.112