Create a hitbox for the sword attack

Taking advantage of inheritance, developing other enemies and their basic movements were fast.
Now I start to focus on what concerns the attack phase of the player and then the enemies.

As always the interaction between two game objects is through the collision or triggering of them that allows us to recognize the object with which we have come into contact.
But at the moment our sword movement is not able to do that because the only collider we are using is on the player.

As a first thing, we have to build a collider for our sword that will be our “Hit Box”.

My sprite with the 2D collider

To build that collider we are going to create a new sprite and we will understand shortly why we assign a default sprite provided by Unity and add a 2D collider. Once this is done we insert the newly created sprite as a child of the main sprite of our player. If you don’t see the sprite is because you have to put it on the same “order in layer” of the player.

The second point concerns making our collider2D follow the movement of the sword. To do this you only need a little patience but it is not at all complicated. Let’s exploit the recording function of our animation. We associate step by step the movement of the animation of our collider.

At the end of the procedure, we should have that to every frame of the animation of attack, the collider results always well superimposed to the same sword.

project manager by day, unity developer by night