Daily progress — skeleton cooldown

Esteban Ibarra
2 min readAug 20, 2021

Oftentimes when creating an animated hitbox collider, Unity will register multiple hits from one attack, and that’s actually normal since you are putting a new collider hit box every fraction of a second, and if our attack is 16 frames a second, we’re going to have as many as 16 collisions on an enemy if we put a new Collider every frame!

So what to do? We’re going to have to create a ‘cooldown’ type system for our attack:

Attack Code:

So if the collider is triggered, then we’ll immediately turn it off for a short while, like half a second to give time for the animation to play out and get ready for the next swipe, if any.

We’ll definitely need a boolean so let’s call it _canHit, and we’ll initialize it as true.

Next, we’ll use _canHit to give permission to the if statement (since it’s true) to go ahead and run the hit.Damage() function, but immediately after set it to false, so that the next frame, the if statement will fail and no longer run the hit.Damage.

This does leave us with the question of when we’ll reset it back to true. Since we know we want to give half a second, we’ll be using a co-routine so let’s initialize one:

With our coroutine initialized, it will wait .5 seconds, and then reset _canHit, which is just enough time for our player to swing completely and wait for the next one!

3 messages of being hit and everything is working as it should! Now we can implement the actual hit animation!

--

--