Attacking with Hitbox- Game Dev Series 104
Objective: create a hitbox attacking system.
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.