Hitbox attack system in Unity 2D

  • Select the player and create a new sprite as a child gameobject called HitBox. It will be the sword’s collider.
  • Place the HitBox as a child of Sprite. I will use the orange color as reference, but this SpriteRenderer will be removed later.
  • Add a Box collider 2D
  • Select the sword’s attack animation and lock the animation’s view
  • Place and modify the HitBox as desired in the first frame
  • Start recording
  • Modify its values in each frame. In the last frame, disable the BoxCollider2D
  • Delete the HitBox’s SpriteRenderer component
  • Set isTrigger to true in BoxCollider
  • Add a Rigidbody2D and set the Gravity Scale value to 0
  • Create an Attack script and attach it to HitBox gameobject




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Developer bounty plan.

Computer Science — 101

Accept Payments by Text Message

How to ssh to your Ubuntu Machine on Virtual Box

Now entering Javascript.. Lord help me *facepalm*

An initial example of Input Error Handling with ZeroDivisionError in Python

Experimenting with Corda Attachments

Launch Message App Like Telegram that works faster than light

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
Hernando Nieto Jaramillo

Hernando Nieto Jaramillo

Unity developer

More from Medium

Let’s Make A Player

I think you dropped something — Creating a simple loot drop system in Unity2D

Post Processing in URP for Unity 2020

Cinemachine: Look At and Body