Creating a Specific Collision Area on a Larger Sprite

Hi Everyone,

First time poster on these forums so I hope somebody is able to help or point me in the right direction.

I’m currently writing only my second ever java game from scratch, not using a framework of any kind yet (maybe that would help with this issue), but have run into a problem that has me a little stumped. ???

The game i’m working on is a missile command style game, however with real missile sprites raining down on city sprites. Now I have my AffineTransform rotating my missiles to the correct angles (which are randomly generated) based on a start and end X and Y (again both randomly generated) BUT my bounding box for each missile is obviously not rotating with the missile. The even bigger problem is that even if I get the bounding box to rotate to envelope the image the image itself has too much blank space either side which would count as a collision when none actually occurred.

Is there some way for me to implement a smaller bounding collision box for my larger image which also follows the rotation of that image?? If only the tip of the missile counted as a collision instead of the whole missile that would be a bonus!

Thanks! ;D

Why is rotating the bounding box a problem? If the original bounding box was ok why would it be too big when rotated?

At the moment my missile image is 40 x 40 but the actual missile is only around 40 by say 12 with the rest being transparent. The reason I changed it to 40 x 40 was so that when I used AffineTransform the rotation worked, whereas when the image was 40 x 12 the rotation would not work correctly.

If this is the problem then I can post my code and maybe somebody can point me to the correct way to rotate a 40 x 12 image the right way along with the bounding box?

You can also make your collision area using a Polygon. Or, building it from multiple Circles/Rectangles. The benefit of the latter solution is that you can use sequentially smaller “level of detail” for more efficient collision checking. Here’s an image to demonstrate:

The image is taken from this great e-book, which is a great resource if you plan on writing your own 2D collision detection:
2D Game Collision Detection - Thomas Schwarzl

Yes this is exactly what I need :smiley:

Although I will definitely buy this book, probably next week, is there any other resources that I can look at online that will explain how to achieve this same thing so I don’t have to wait?

Its a kindle book so you don’t have to wait anyway :slight_smile:

Are you offering to pay?? :stuck_out_tongue:

No need to buy a kindle just use the app!

;D I meant the money for the ebook… Anyway thanks for the link, as I said I will buy it sometime this week when I have some money in my paypal account (it’s easier for me to do it that way).

I’d still appreciate any other links to similar solutions?! :wink:

Depending on your needs, the solution posted by davedes is fast and good enough(I used something like that on my nintendo ds game called “bubble fight ds”).

You could also use aabb or sat or a combination of them all.

A hierarchy of bounding circles is a fundamentally flawed solution assuming you want accurate and fast “intersections”. And why on earth do people always forget about GJK.