Hitbox Attack System Unity2D

addam davis
3 min readDec 1, 2021

Objective: Create a Hitbox for the Player’s sword!

In this tutorial we are going to focus on setting up a hitbox for our player’s sword. We are going to be animating a collider with the sword so it is going to swing and a collider is going to be moving with it.

We are going to begin by right clicking our player and creating a new sprite.

I named mine “Hit_Box”

This is going to be the collider of the sword and it’s going to be animated with our sword swing. We need to set the order in layers to be the same as our player, for us that is 50.

Under sprite select the circle button and select the default sprite UISprite.

Add a box collider 2D

This is going to allow us to take the shape of the sword. We need to child the hitbox to the player’s sprite object.

This will allow us to manipulate the attack animation and the hitbox together at the same time as well as animate the hitbox without needing to give it it’s own animator controller.

Select the animation view and the attack animation.

With the first frame selected press the record button. Select the hit box and stretch, place, and rotate it over the sword.

Move to the next frame and adjust the hitbox to stay over the sword.

We need to do this for every single frame.

The sword no longer swing in front of the play so we can leave the hit box there for the remainder of the animation.

With this animation finished we have successfully create a hitbox for a player’s attacks. In the next tutorial we are going to create a script for our player’s attacks. Don’t be afraid to experiment with your mapping and I’ll see you in the next tutorial!