Daily progress — Implementing the Skeletons Hit animation

Esteban Ibarra
3 min readAug 21, 2021

We’ve now written a working attack and damage system, it’s time to implement the hit animation. First, there’s a minor fix in that we need to make a transition from hit to idle, and zero out the transition time. (Leave exit time alone though)

Now we just need to access the animator and set the ‘hit’ trigger. Fortunately, the animator is already set up in the base enemy class:

Let’s see if it works:

The hit is working, but the skeleton is still moving left and right while playing the hit animation.

In our enemy code, we’re constantly moving. We need to put in a way to stop moving when we’re hit. We’ll begin by creating a boolean that says if we’re hit or not.

Enemy Code:

And now in our Skeleton code, when we’re damaged, we set it to true.

Back in our enemy code, we now wrap the movement with the isHit:

If all goes well, the skeleton will stop moving when he’s hit!

Great! The skeleton’s stopped moving. It’s going into the walk animation but that’s expected as it automatically transitions into it. We’ll need to keep our skeleton Idling so he can attack, this would be a good time to create a new boolean in the Animator window called ‘InCombat’, and we’ll transition to walking only when we’re out of it.

Turning on InCombat in the animator will have our skeleton happily idling, turning InCombat off will let the skeleton walk again. Everything’s working great!

Now all we need to do is set off ‘InCombat’ to our skeleton in code, the most natural place would be in damage:

Now let’s give our skeleton a good whack and watch him stop!

Awesome! Our skeleton now reacts with a hit and stops! I think this is a good point to stop the daily log, tomorrow we’ll give our skeleton the ability to walk again and maybe fight back. see you tomorrow!

--

--