Sprite based fighting game collision?

Hi, all. I’m starting to work on a sidescrolling action game where the player will be able to jump around and attack enemies.

Ideally I’d like for hit detection to be based on sprites. So if [hitbox sprite] overlaps [hurtbox sprite] then a hit took place, where the hit and hurt sprites can be animated alongside the characters themselves. But I’ve been searching and can’t find any tools for doing that. Is that a bad idea and/or unfeasible?

If so, what are best practices for using regular 2d trigger volumes as hitboxes? Do I instantiate them when the attack button is pressed, or do I just attach them do their parents and turn them on/off when needed?

create us an image of your idea so I can get a better idea of what you are trying to do.

I would recommend using child objects for the player each with all colliders belonging to a certain body part, such as arm or leg. With those you’ll be able to detect exactly what collides with what, not just pixel collided with pixel, if that’s even possible in Unity. You can use combination of circle, box and polygon 2D colliders.

Here’s a representation of what I’m talking about. Ideally I’d like hitboxes to be defined by sprites like this

If that’s not possible, then the alternative is using trigger volumes like this

If I’m using trigger volumes, should I create them and delete them as needed? Or do I just need to have every possible trigger volume for every attack sitting in the character, to be turned on and off as needed?

I would possibly prefer CircleCollider2D for that kind of hit. Match its animation (radius and position) with the Animator UI, same thing can also enable/disable the colliders as the frame starts and ends.

Yes I agree with Zaflis on this, you can have a method called when the animation is finished, it can be a little fiddly if you don’t automatically add the script before hand(“you can add the script to the gameobject in code”), if you want this to happen add the script first link the animation method to the script method, and delete the script from the gameobejct, and just add it in code it will still call the animation method and script method.

But you don’t need a script for just this, the animation can change numeric values of objects, but also booleans such as boxcollider’s enabled property.

Actual hit detection would happen with the physics engine of Unity through the OnTriggerEnter event.

If it is too complicated to understand just read a text as written above then I would recommend you to watch this tutorial which has simplified animations&behaviours topic.