Search Unity

Help with MUGEN like hitboxes

Discussion in '2D' started by Kinos141, Nov 15, 2013.

  1. Kinos141

    Kinos141

    Joined:
    Jun 22, 2011
    Posts:
    969
    I'm trying to figure out the best way to create mugen like hitboxes on a game character attack animation, like chun-li's kicks. Does anyone have an idea how to do this? THe example project is a gun game. Also, the sprite I'm using is one sprite, no separate parts. So I can't attach a collider easily.
     
  2. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    3,149
    I don't know for real, but maybe you could instantiate a game object with a hit box attached to it when the attack animation is run? There's the new Animation Event system (which I haven't used yet), and perhaps at the right point in the animation the box can be created for hit detection.
     
  3. zerotri3

    zerotri3

    Joined:
    Nov 14, 2013
    Posts:
    5
    My suggestion would be to create a few colliders for your character. Circle colliders for the hands, feet and head, a few box colliders for the body, arms and legs, each contained in a child object of the main character with the IsTrigger checkbox set (though with unset you can have them be used in affecting the physics positions of other objects).

    $Screen Shot 2013-11-18 at 1.05.34 AM.png
    This image shows the object hierarchy with all of the subobject's colliders displayed. Note that the Sprite Renderer component belongs to the main Fighter object.


    $Screen Shot 2013-11-18 at 1.08.31 AM.png
    This images shows one of the single body piece objects, with the Circle Collider 2D component on it.

    With a setup like this, you could then create animations for the Fighter object that affect it's sprite and all of the subobject transforms. Add a script to control the character, and an enemy with a similar setup that has a script that reacts to physics2D collisions and you should have the basic setup for a fighting game.

    Hope it helps,
    - Wynter Woods