Unity Development — Hitbox

If you are at all into fighting games, I am sure you have heard people talking about hitboxes before. Maybe even a little too much. Now you are finally going to understand everything they are talking about. Well… maybe not everything.

Say we have a Player object and they have an attack animation. We are going to have a hitbox be a child of that object and they will be adjusted in the attack animation itself, simulating the swinging of a sword, a full kick, a punch, or any other attack with movement.

In my project, the Player’s animations are controlled by a child called ‘Sprite.’ That is just fine. As long as the hitbox is a child of whatever object is holding the Animator.

Your Hitbox should have a Collider and a Rigidbody to detect collision. Make the Collider a trigger.

In the Inspector, you should also set the hitboxoff at the top.

In the Animation window, go to your Attack animation. For every animation you can hit the Record button (red button next to ‘Preview’) and make changes to attributes in the Inspector. Because the hitbox is a child of our object with the Animator, it applies there as well.

Go to the first frame, hit Record, and set the Hitbox to be enabled on the Inspector. You will see that it sets a new key in the animation window and has recorded. Still in the first frame, move the hitbox’s transform and edit the Collider to properly encompass what you wish to be the area of attack. In our case, it is around the Player’s sword.

It is going to be tedious, depending on how many frames you have, but you must do this for each frame of the animation. And be sure that you are in Record mode the whole time. Make it as precise as you wish, or leave some wiggle room.

Do lots of play testing after setting up your hitboxes. You never know if someone is going to come around and say they are unfair because one reason or the next. Luckily we live in a world with online updates, so even professionals need to readjust sometimes.



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