Search Unity

How to properly implement hurtbox, hitbox, pushbox and the like?

Discussion in 'General Discussion' started by halfblue3, May 8, 2022.

  1. halfblue3

    halfblue3

    Joined:
    Mar 5, 2019
    Posts:
    11
    I'm already on my slow journey of studying game dev where I want to implement "the boxes". I know what they do and a general idea of what I need to implement them. But after researching, I found out that it isn't that simple. Colliders alone won't give the best detection. And you need a RigidBody paired with the Collider? Because it affects the engine's performance? I found this amazing article which was really informative to me: https://strangewire.blogspot.com/2018/05/hitboxes-and-hurtboxes-in-unity.html. But, the problem is, this only talked about the code side, not how/where to place Colliders. My instinct was to add them as a child of a bone so it moves without animating them again, disable/enable the GameObject with the Collider when necessary. But after my research, I'm not really sure if that's the right thing to do anymore.
     
  2. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    No, you dont need Rigidbodies for this type of hit detection. Collider can be marked as Trigger and then do things using OnTriggerEnter script update keyword.
    And a known problem with placing colliders on bones is fast animation. It is easy to run into situation when the bone completely passes through a target between two animation frames, and doesnt register a hit. Using such setup will require an additional hit test, like storing the position of a bone on a previous frame, and then tracing BoxCast or SphereCast backwards to that position
     
  3. halfblue3

    halfblue3

    Joined:
    Mar 5, 2019
    Posts:
    11
    Oh, thanks for that additional explanation. I did read about that somewhere. Thanks, now I have some pointers I can use to plan how to implement the boxes
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,635
    Yes, exactly.
     
  5. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Also 'boxes' can be dissociated with animation, some game parent them to the root for fixed placement (like always in front of character), really depend on your game design.