Search Unity

Colliders moving with animation

Discussion in '2D' started by hasen, Apr 27, 2015.

  1. hasen

    hasen

    Joined:
    Apr 1, 2015
    Posts:
    29
    I've added some colliders for hitboxes and the like to my spritesheet animated character but when he moves, the colliders don't move with him. So for example if his head moves back, the head hitbox doesn't. Of course I can do it all manually but is there any way to get them to go automatically?

    Or if not is there any asset that does this perhaps?
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    You could try setting the offset of your colliders along with the sprite animations using the Animation window.

    This is still manual as you would need to link the head position with the head hitbox.
     
  3. hasen

    hasen

    Joined:
    Apr 1, 2015
    Posts:
    29
    So when they are linked they would move with the animation? How do I link the head to the collider?
     
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    You could link the collider to the head by setting the offset position to the position of the head. You would need to manually adjust the offset for all the following frames as the head moves.

    In the following, the collider is offset to the position of the pickaxe, and changes as the pickaxe moves down in the following frame:
    Offset.png
     
  5. hasen

    hasen

    Joined:
    Apr 1, 2015
    Posts:
    29
    Ok but that's not really linked in any way is it? That's what I'm currently doing as far as I can see. I just move the colliders manually along with the animation frame by frame. Thanks for your help anyway.
     
    Last edited: Apr 29, 2015