Jump to content

  • Log In with Google      Sign In   
  • Create Account


Hitbox on irregular objects


Old topic!
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.

  • You cannot reply to this topic
10 replies to this topic

#1 vastrolorde   Members   -  Reputation: 110

Like
0Likes
Like

Posted 26 April 2013 - 10:08 AM

How to i create a hitbox for irregular objects.



Sponsor:

#2 Paradigm Shifter   Crossbones+   -  Reputation: 5250

Like
0Likes
Like

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

 

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, 26 April 2013 - 10:13 AM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#3 Dan Mayor   Crossbones+   -  Reputation: 1712

Like
0Likes
Like

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?


Digivance Game Studios Founder:

Dan Mayor - Dan@Digivance.com
 www.Digivance.com


#4 vastrolorde   Members   -  Reputation: 110

Like
0Likes
Like

Posted 27 April 2013 - 04:47 AM

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.

Boss4


Hitbox for this


#5 Paradigm Shifter   Crossbones+   -  Reputation: 5250

Like
0Likes
Like

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.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#6 vastrolorde   Members   -  Reputation: 110

Like
0Likes
Like

Posted 27 April 2013 - 05:04 AM

so basiclly, the more precise hitbox i want the more sections i mustm ake



#7 Paradigm Shifter   Crossbones+   -  Reputation: 5250

Like
0Likes
Like

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.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#8 vastrolorde   Members   -  Reputation: 110

Like
0Likes
Like

Posted 27 April 2013 - 05:39 AM

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?



#9 vastrolorde   Members   -  Reputation: 110

Like
0Likes
Like

Posted 28 April 2013 - 04:06 AM

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



#10 Paradigm Shifter   Crossbones+   -  Reputation: 5250

Like
0Likes
Like

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.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#11 vastrolorde   Members   -  Reputation: 110

Like
0Likes
Like

Posted 02 May 2013 - 04:27 AM

Can i do pixel perect collision with imageicon or do i need to use buffered image?






Old topic!
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.



PARTNERS