0.6.4 update: better collision areas

working on the whale mini-boss, I quickly realized that I needed a better way to handle collisions. until now, all creatures’ hit boxes consisted of a single rectangle equal to its sprite size. this has worked so far, where things are relatively small, and I’ve been keeping things mostly-rectangular.

in fact, I choose the sperm whale as a base for this latest mini-boss precisely because of its relatively boxy shape!

but then I ran into an issue: the whale’s tail!

Hiding Place

there is no way to fit a single rectangle around this creature in a “reasonable” way – a way the player will intuitively understand. in the above picture, if there’s only a single collision rectangle for the whale, either the player needs to be taking damage, or the rectangle needs to be so small that the whale’s tail can not be collided with at all.

this will clearly not do! so I finally did what I probably should have done a while ago: allowed things to have any number of collision rectangles, of any size and position.

Whale Collision Rectangles

using only rectangles is still a bit restrictive, as many shapes may have angles or curves that a rectangle does not neatly fit, but this is “good enough”. if you doubt it, think back to the NES/SNES/Genesis era of games, where rectangles (or possibly circles) were used almost exclusively for determining collision. even games on the first generation of 3D consoles often used simple rectangular prisms and/or spheres.

there are a couple additional things to consider, though:

first, you CAN break something down into ANY number of rectangles. on the NES/SNES/Genesis this might have been a serious issue of accuracy vs speed, but modern PCs are a touch more capable 😛 for Mysterious Space, we could break things down into very many, very small rectangles, if needed. for example, consider the first miniboss, who is made of 48 independent parts, each with a single collision rectangle. if there were no performance issues with that (and there weren’t) then it stands to reason that we could safely give the whale 48 collision rectangles without any hit to performance, allowing a great deal of precision on the slopes. (though I’ve chosen only 5, simply because 48 would be overkill!)

megamansecond, where there ARE inaccuracies, it is best to err on the side of kindness to the player. you can see this in many old games. the MegaMan games are an example I specifically remember reading about, where the collision rectangle for MegaMan is intentionally quite a bit smaller than the full area his sprite takes up, meaning bullets can graze his feet, top of his head, or hand, without registering as a hit. this may seem inaccurate, but as you make the collision rectangle larger, you run the risk of bullets hitting the player when obviously they should not.

you might, then, ask: is it better to have bullets miss that “should” have hit? or bullets hit that “should” have missed? the answer is “whatever makes the player feel better” 😛 it is MUCH better to have the player feel that they dodged a bullet that “should” have hit than to have the player feel the game is being unfair by having bullets hit that should NOT have.

shoot ’em ups like Ikaruga are actually fantastic examples of this, as well, where a hit is only registered at the very center of your ship; the wings, apparently, are merely decoration.

on the flip side, ENEMY collision boxes should typically take up closer to the full sprite space, so that the player doesn’t feel cheated by a bullet that SHOULD have hit.

again, when using a very few number of rectangles, it is inevitable that the player will observe inaccuracies in one way or another. the human brain is much happier when things are unfair in ITS favor, so for most games, err on the side of being nice to the player.

at the time of this writing, the only thing in Mysterious Space with a collision area that is not a single rectangle taking up the full sprite dimensions is the new whale mini-boss. but code is now in place that will allow me to easily override collisions areas for ANYTHING, replacing one, full-size collision rectangle with any number of collision rectangles of any size. for the most part, I will probably leave most things alone – bullets, for example, are all small and of regular shape, so their “default” collision areas are fine – but I’ll definitely look everything over and see if there are any obvious improvements to make, and I will DEFINITELY go over the players and more-precisely tune their collision rectangles.

thanks for reading 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s