How to i create a hitbox for irregular objects.
Hitbox on irregular objects
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
http://stackoverflow.com/questions/8721406/how-to-determine-if-a-point-is-inside-a-2d-convex-polygon
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.
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?
Im using the standard JDK. and ima lasousing java swing. Im trying to accoplish thet i can shoot through the tenticles to hit the eye. Atm it jsut hit the rectangle edge that surrounds the creature.
Hitbox for this
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.
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.
OK. i think i can use the polygon. is there a way to automatically get the X and Y coordinates for my shape or do i have to get em manually?
Or do you have a better suggestion for getting the x and Y coords, cause manually getting em would be quite hard and my monster also moves around
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.