Results 1 to 5 of 5
- 08-19-2013, 03:17 PM #1
Senior Member
- Join Date
- Mar 2013
- Location
- Greece
- Posts
- 183
- Rep Power
- 8
More Advances Collision detection
Hello Guys... i Hope this time i make the post in the right section :P
i need to know if there are more advances ways to chech about the collision between two bufferedImages For example.... in my project to chech about the Collision i use the ordinary way with creating two Rectangles and then just check if one intersect in other..
but there are some problems one like this :
by Creating two Rectangles is really hard to understand from what side the images collides
then i try to Create a 2D line for each side (Left , Right , up ,down) then to check which one of the collides first then do what i want.. but if you chech the image above what will happen if the image collides with the up left corner ? it depends of that line will collide first..
to solve this problem (with my low knowledge) i do something like that :
but this is very bad idea.. i have a lot of enemies characters.. so this is very confusing...
then i read something about Per Pixel based collision detection and XNA but i don't really understand what is going on.. so i need help .. :P
every info will be useful ;)
thx in advance!
- 08-19-2013, 03:26 PM #2
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: More Advances Collision detection
The way I deal with the bounding box problem is to add pixel perfect collision detection. So collision detection is a two-phase check:
1) do the bounding boxes overlap?
2) when they do, do any actual pixels of the entities overlap?
Step 2 is the one that makes programming difficult, how the heck do you do that?
I did it by creating a dumb array of booleans for each frame of each bob (bob = an animating sprite) where each index represents a single pixel in the image; it would be true if the pixel is opaque and false if it is transparent. Then all I needed to do was compare the parts of the array where the bounding boxes overlap (again: very much not easy) to see if one of the cells that are on top of each other both contain the value true. If so: DEATH!
EDIT: eh its a bit confusing what you're after actually. You are also talking about a direction. But depending on the location of the pixels that touch each other, you should be able to work out a rudimentary collision location too. I take it you want to be able to check if it is death for you or death for the enemy because you jumped on its head :)Last edited by gimbal2; 08-19-2013 at 03:31 PM.
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 08-19-2013, 08:47 PM #3
Senior Member
- Join Date
- Mar 2013
- Location
- Greece
- Posts
- 183
- Rep Power
- 8
Re: More Advances Collision detection
Remarkable Answer... Thanks for the informations!! i am going to take a look at them right now ;)
Google is my best friend ;)
- 08-20-2013, 12:23 AM #4
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: More Advances Collision detection
yeah well in this case not too much, this is something that basically everyone reinvents for himself :)
Did I ever point you to java-gaming.org? Its a website where basically all Java developers that do game development congregate (some even that SELL games they build using Java, which is quite an amazing achievement). There you can find tons and tons of questions and examples on doing not only collision detection but basically everything else too. You probably know Minecraft? It basically started there. You can still find the old thread where Notch was sharing his ideas and was asking for advice."Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 08-20-2013, 12:56 AM #5
Senior Member
- Join Date
- Mar 2013
- Location
- Greece
- Posts
- 183
- Rep Power
- 8
Similar Threads
-
Need Help With Collision Detection
By scotthdez in forum New To JavaReplies: 2Last Post: 07-24-2013, 07:01 PM -
Collision Detection
By Äppelpaj in forum Java 2DReplies: 1Last Post: 10-13-2011, 04:29 PM -
Collision Detection
By sunde887 in forum Java 2DReplies: 2Last Post: 10-08-2011, 12:40 AM -
Collision Detection?
By Alerhau in forum New To JavaReplies: 39Last Post: 09-07-2011, 05:55 PM -
Collision Detection
By dotabyss in forum Java GamingReplies: 0Last Post: 03-14-2010, 07:13 PM
Bookmarks