Attacking with Hitbox- Game Dev Series 104

Objective: create a hitbox attacking system.

See the green box on sword?

As we created the sword swing animation in 2D game to attack, how do we make it works like a real sword attack?
As always, we use collider as trigger.
In this article, we will create a hitbox attacking system to attack animation.

Hitbox collider

To create a hitbox, first we need a sprite. Add one to Player and set the sprite to UISprite as base sprite.

Then add a box collider 2D and a Rigidbody 2D to it and set collider as trigger.

Attach to attack animation

Then select Player Sprite object and choose Attack animation in Animation tab. We will adjust the Hit_Box to Attack animation frame by frame.
Before we do it, drag Hit_Box to Sprite as a child of it.
And remove the Sprite Renderer component of Hit_Box.

Then we can start adjusting Hit_Box in Animation.
When Attack animation is recording, moving and rotating Hit_Box to make it fit the sword in animation.

When it done, it should look like this.

Now you have created a hitbox to Player, in the next article we will continue to make this sword works.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
S.J. Jason Liu

S.J. Jason Liu


A passionate gamer whose goal is to work in video game development.