Search Unity

Dynamic-shape hit detection?

Discussion in '2D' started by Marscaleb, Oct 29, 2014.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,037
    I'm designing a character who will attack with a wide sweeping strike.
    I don't have the animation finished, but I already know that it will be a somewhat irregular shape, and I'm wondering what the best way is to actually check if the attack hits anything.

    By way of example, the attack will look something like this:
    http://www.sprites-inc.co.uk/files/Zero/Zero/Sabre/zero_z3sabresheet.gif
    Although with a slightly longer warm-up where the attack

    Previously I had been using a simple box and checking to see if anything comes in contact with said box. But the sweeping motion isn't going to fit into a perfect rectangular box very well.
    *Maybe* I could create a polygon collider, but that just doesn't sound like an efficient way to go, especially since I'd need a separate object with its own collision for each different animation, all of them permanently attached to my character and dragged around everywhere.

    Besides, I'd really prefer something that can change for each frame, so I can check for hits along the sweep each frame, rather than checking the whole sweep at once. (If I can manage it reasonably.)