Hitbox/Collision Detection on angled/offset sprite

Started by
2 comments, last by manelis 11 years, 8 months ago
Hi there
my project is in the attachments.

I'm trying to write a basic dualstick shooter test. Unfortunately I only have the gamepad implemented right now, so testing things out might be hard for people that don't have an x360 controller (I'm attaching screenshots and video though to make matters a bit clearer).

My problem at the moment is the collision detection. I have my sprite "arrow" drawn at an angle i calculate within the "Projectile" class but of course the Rectangle I use to draw the arrow (projectilebox) and to calculate the collision doesn't rotate with the sprite (as shown in the following screenshot):

http://oi47.tinypic.com/aw5l5u.jpg

Besides that the projectilebox itself drawn without any origin or angle values seems to be very far away from the actual arrow i draw.

My collision detection at the moment basically consists of checking whether the hitbox of the ship (shipbox) intersects with the projectilebox, but as this is not in the proper position, the detection is way off :S

So basically my question is: How do I align the projectilebox to properly fit to the sprite (arrow) I draw?

btw: The controls for the executable are: LStick: move ship, RStick: aim, RShoulder: shoot
CAUTION:
As soon as the projectilebox hits the shipbox I make the game crash/freeze to be able to see where the box actually hit the ship (this is probably very bad programming, right? biggrin.png)
greetings

//EDIT:
Here is a video so you may be able to see it a bit more clearly:
Advertisement
Why is your box so far away from your arrow?

The way it's usually done is you'd have a bounding box for your sprite, just like the one you have now. If the bounding boxes collide, you would do a per-pixel test for accuracy. This looks like a good reference:

http://create.msdn.com/en-US/education/catalog/tutorial/collision_2d_perpixel
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
But the bounding box can't be angled, right? So when I rotate my sprite the bounding box is not accurate anymore.

//EDIT:
Thanks for the link though, I'll read through it ;)

As soon as the projectilebox hits the shipbox I make the game crash/freeze to be able to see where the box actually hit the ship (this is probably very bad programming, right? )


You can put a breakpoint in the line that makes it happen (on VS click on the left border of the screen, on the side of the line number).

This topic is closed to new replies.

Advertisement