Search Unity

Implementing Hitboxes in game

Discussion in 'Scripting' started by Robster95, Jan 28, 2021.

  1. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    So I'm working on a top down shooter where if the player doesn't have a weapon he is able to punch and aliens run at the player and attack with either weapons or their claws.

    I'm debating on the best way to implement hitboxes and can't seem to find anything online. Is it better to do,

    1. Make a collider[] in code and simply change the position and size of the collider when an attack is called

    or

    2. Make an attack animation and have the animation change the hitboxes size and position to have it sync up with the attack and also make it stay active for a certain amount of frames?

    If someone is able to help shed some light on this that would be GREATLY appreciated!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Are you sure? Have you fully worked through even ONE of the videos on the first page of googling for unity hitboxes?

    Screen Shot 2021-01-28 at 7.02.09 AM.png

    Pretty much any solution to this problem would map analogously either in 2D physics or 3D physics.
     
    Robster95 likes this.
  3. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    I meant I found videos that explain but I’ve heard from multiple people there were different methods but didn’t really find any explanation on which method may be better.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Even if you found such an explanation, would it be useful in your vaguely-specified "top down shooter" case?

    I would just try something, if it doesn't suit you, try something else.

    When you don't know anything about a domain, that is a tried and true and fairly easy way to learn a lot about it.

    Plus who knows? You could become the new domain knowledge expert on hitboxes! Your name in lights, "Rob 'The HitBoxMeiSTER95" !
     
    Robster95 likes this.
  5. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    Haha I’ll for sure do that and get that title man! Lol