Sign in to follow this  

Hitbox/Collision Detection on angled/offset sprite

This topic is 1960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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):

[url="http://oi47.tinypic.com/aw5l5u.jpg"]http://oi47.tinypic.com/aw5l5u.jpg[/url]

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? [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img])
greetings

//EDIT:
Here is a video so you may be able to see it a bit more clearly:
[url="http://www.youtube.com/watch?v=9YRCvhs9d5E&feature=youtu.be"]http://www.youtube.com/watch?v=9YRCvhs9d5E[/url]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 ;) Edited by fuerchter

Share this post


Link to post
Share on other sites
[quote name='fuerchter' timestamp='1343646243' post='4964448']
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? )
[/quote]

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).

Share this post


Link to post
Share on other sites

This topic is 1960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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