Hitbox

i got a question.
is this the hitbox? (all the yellow area)


or the hitbox is the whole square/rectangle

3 Likes

VERY good question, @Mega0star01!

I am trying to wrap my head around this myself in this very same moment…

Anyone?

3 Likes

It’s the yellow area, not the whole thing

1 Like

actually i have no idea, im pretty sure its the whole rectangle though…

1 Like

Sprite overlaps are computed using the image, so transparent pixels in an image do not count towards overlaps. So the hitbox is in the red outline in that image.

3 Likes

that yellow area is the hitbox. (i think)

1 Like

The answer is both.

Sprite overlaps are based on the pixels in the image (transparency is ignored). In other words, the yellow area of your example

Tilemap overlaps are based on the outer rectangle of all filled pixels in an image. For your example, that would be the entire outer rectangle of the sprite. For an image like this one:

…it’s the red rectangle (the rectangle around all filled pixels).

3 Likes

Here is an example program that shows the sprite overlap behavior:

The background turns orange when the sprites are overlapping.

And here is another example showing off tilemap behavior:

Note that the sprite you are moving around has a huge transparent chunk in the middle but it still can’t pass through walls and the transparent area still overlaps with tiles

5 Likes

thank you so much, i needed this answer for a fighting game.

2 Likes

Great to know! Just one question… why?? Why not make it pixel perfect for both?

3 Likes

@Sarge good question!

The primary reason is to stop you from getting caught on walls. Imagine you have a character like this:

If they were in a platformer and walked to the edge of a platform, you wouldn’t want them to get caught on their arm or the brim of their hat on the way down. You’d want them to behave like a rectangle.

The second reason is performance. Pixel perfect overlaps are expensive to check; you need to iterate over the pixels of both images to see if there are any two that touch. Meanwhile, rectangle checks are cheap!

6 Likes

You do have a point, after all if I do need pixel perfect collision checks I can just code them myself :weary:

(I mean, on a project to project basis that is)

3 Likes