Sign in to follow this  
Sivak

Hitboxes - Circles or Rectangles? Considerations...

Recommended Posts

Sivak    140
Hey all. I'm making a Shmup game. I've been toiling with this and have considered going to circular hitboxes. It seems that the checks for those are faster, but at the same time it seems that I'll have to use floats, especially for them to be in the center of an object. It doesn't seem too complicated, but I just wanted to get things straight before doing this. The player is 28x32... Right now I'm just using a 2x2 hitbox, which would be located, within the sprite, starting at 0,0: 12,14 to 13,14. (Yeah, it's positioned a little ways up. Horizontally centered though. With a circle, I'd have to use 12.5 and 13.5 and then have a radius of 1? Another thought: Is it normal to use circles for these type of games due to the speed of checking? I recall reading that circles vs. circles are easy, but circles vs. other shapes are annoying... Advice appreciated, thanks.

Share this post


Link to post
Share on other sites
diablos_blade    257
Circle vs Circle tests are very fast, but so are Axis Aligned Box vs Axis Aligned Box tests, and Circle vs AABB tests. It is normal to use the simplest collision shape you can get away with using, which depends entirely on the shape of your collideable object.

If, for instance, your player or bullets are pretty much circular, then using a circle for a collision shape is your best option. If they are a box (that never rotates), then an AABB would be a better option because it is a closer match for the underlying object. In other cases you may have to use a more collision shape, but I doubt you would need to for a Shmup.

But, is the only reason you are considering this change because of speed? If so have you profiled your code to make sure that your collision checks are your bottleneck? Theres no real point in optimizing (and in this case, I doubt it would be much of optimisation, if any) code that it not causing your game to run slowly. If however you want to switch so you can learn how to check for collisions between circles, then by all means, go right ahead [smile].

Share this post


Link to post
Share on other sites
Sivak    140
Well, no. The speed isn't an issue... yet... heh. It seems the circles just may be more accurate is all. I just was worried it could make some things complex.

Right now it's just a core engine. I'm trying to figure out why the game runs faster when it has more to update rather than very little. o_O

Share this post


Link to post
Share on other sites
Palidine    1315
Quote:
Original post by Sivak
I'm trying to figure out why the game runs faster when it has more to update rather than very little. o_O


What does your profiler say [wink]

-me

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this