How to i create a hitbox for irregular objects.
Jump to content
Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 26 April 2013 - 10:13 AM
Depends if you want a bounding box (find max/min x and y extents of the object), or if you want an irregular shaped region, in which case you want a point in polygon test, here's one in Java
and that also mentions this:
The java.awt.Polygon class has a number of contains(...) methods if you use Polygon objects to represent your polygon.
Edited by Paradigm Shifter, 26 April 2013 - 10:13 AM.
Posted 26 April 2013 - 10:34 AM
Vastrolorde, you will need to provide more information as to what you are trying to accomplish, what you have tried and how you are hoping to solve your problem. Perhaps try to define what you mean by irregular objects, what engines and or libraries are you using?
Professional Programmer & Hobbyist Game Developer
Posted 27 April 2013 - 04:51 AM
You're probably going to be better off if you split the enemy up into 3 sections... top bit, eye part and bottom bit, with separate collision for each bit (presumably it only takes damage if you hit the eye). You can probably just use rectangle collision for the 3 parts then.
Posted 27 April 2013 - 05:09 AM
If you want to use rectangles, yes. You could also use a hierarchy of rectangles that fits the shape better. I suggest different objects since the collision is probably handled differently for the eye vs. rest of the enemy.
Or you could use a polygon collision method, I linked to some code for that in my first post.
Posted 28 April 2013 - 04:24 AM
You mean the texture animates?
You could do pixel perfect collision if you looked up the texture at the bullet hit position, read the source texture x,y after mapping the bullet position into it and if it isn't the background colour it has hit. You could also use another separate texture with colour coded "what have you hit" info as well (so you could use one colour for "tentacle" and another for "eyeball", say).
It's easiest to have a single "hit position" for the bullet since you only have to do 1 lookup on the texture rather than read a whole bunch of pixels from the enemy texture.
Someone asked a question about computing the 2D concave hull of an image in the maths & physics forum, you may want to look at that thread in case something relevant to your problem pops up.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.