Why Do People Use Separate Hitbox Objects?

Hi there,

In a lot of the example games I looked through, and a lot of tutorials, people make a rectangular “hitbox” for characters that they make invisible and do all the events for, instead of using the built-in collision masks.

Now, I understand sometimes that’s for practical reasons, maybe there’s multiple of that same object, or because they have multiple parts of this sprite they want to have different collision coding (though I believe you can have multiple collision masks and points in an object anyway right?), but when it comes to a simple platformer main character, why do people–like in the Endless Up Runner example game–use hitbox objects that they stick to the sprite, instead of having the collision mask/s built into the main character sprite itself? Is it something to do with Optimization? I figured having more objects that have to move with the main character sprite every frame would not be optimal?

The closest thread I saw to asking about this is here [here](Feedback on Game Optimization). I couldn’t find info about why it’s done, so I apologize if it’s already been answered. This wasn’t a “how do I” technically, so I figured it’s best put in here.

Thank you!

I’m not sure, to me it feels like it does nothing. But I guess maybe for others it’s used for more technical features. That I’m not sure of

I am that kind of person that do not care how something work
I only care that someone leave me option to let me choose how i want something to work
And this fits perfectly
Just to be clear i am not using separate hit boxes

BUT i am using for example variables for any sound i play as volume level instead of some number
I could simply change volume of any sound with action
But using variable i am able to control multiple many sounds volume at once

It is not about is it better or not
But more about how i like to do it and what type of control i want to have

Other example i use variables for zooming instead of setting some value
Not to mention here and with sound i can simply save that to storage and load at will
I have full control over zoom level since i can change it with key press
But also i am able to print that variable to text object o see what current zoom level is

I can clearly see there could be some possible benefits for using separate objects as hitbox
For example you can have different behaviors on hit box and on actual character

I still can’t come up with any practical idea but potential is there

That’s true. Also not really a hitbox but if you wanted to have a top down character with arms that can punch. It being a separate object can benefit. I feel like most benefits are from topdown

There are good reasons for doing that. One is for example here:

2 Likes

Thanks for your input all. I’m also learning that even when your character has separate Collision Masks, it seems that they can’t be used separately in events. I think I am seeing the use for it! (And also understand that it’s not necessary when, well, it’s not necessary haha)

Any other input would be appreciated but I think it’s starting to click. Even with a simple platform character, you may want its feet just to be a hitbox for platforms, while the body to be a separate hitbox. I thought that was already possible with multiple collision masks, but I see you can’t specify which custom collision mask of an object you want in an event

For platformers, there are a few different reasons to use separate collision mask objects:

  1. The platformer character behavior doesn’t care what shape your collision mask is. It takes the widest point and the tallest point to make a rectangle, and uses that for all collision calculations. This is to ensure it doesn’t run into weird stuttering on slopes and other issues. (This is also why you should never change the width/height of your collision mask objects if you can avoid it, otherwise you could end up in part of a wall and cause oddities)
  2. By having a separate collision object with the platformer behavior on it, you can do a bunch of stuff to your animation and not have it impact your movement. Want to ensure that getting touched on the shoulder is a full hit? Put the collision mask of your actual visual sprite to be only in the rectangle shape you want, and only test against that for damage attacks. This would be separate from your movement collision mask (from the hitbox object), so your character doesn’t clip into walls visually.

There are others, but these are the most common for me.

3 Likes

Oh wow! That info about the platformer behavior explains so much!!! Thank you for that info, that not only answered my initial question, but also solved a few headaches I was having. Thanks!