Jump to content
  • Advertisement
Sign in to follow this  
Marko T

Hitbox on irregular objects

This topic is 2055 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

Advertisement

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.

Edited by Paradigm Shifter

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

[sharedmedia=gallery:images:3637]

Hitbox for this

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!