@groundh0g you simply check the distance from the center of the circle to the centre of the other circle and see if its less than the radius of one plus the radius of the other. I'm not sure if that's what you've done, but that's all you've demonstrated. Circles are easy - if you want to demo your code, you need to use more abstract shapes.
Really? The video is of an example program that's developed in a book that I wrote back in 2007.
The example taught the reader how to perform pixel-perfect collision detection. The sprites just happen to be circles. I can assure you that the algorithms support more complex shapes -- for example, it's used in a later chapters when the player blows up spaceships.
Congratulations on your mastery of determining the distance between two points, though. I'm sure that will come in handy.
@groundh0g I can't tell if you are using sarcasm or not, but this sounds interesting. Do you think you could help me with 3D collision? I'm not the best at it. I just assumed you found the distance between two points, due to the fact that they were circles. However, as we all know, assuming makes an ass out of u and ME. I have developed a couple games in my free time, both of which I tackled with a lack of experience. If you checked my vids, you can see how bad I was. Now, working on a new
@groundh0g project, I've gotten a lot better. For instance, I have better terrain collision than I did with the Awakening Engine terrain. That's because I found a better method using rays. You probably had enough of my rambling by now. So could you please send me to some source, such as a tutorial? I would love to learn more about collision, 2D or 3D.
@orangegold1 I'm not trying to be a jerk. It's just frustrating to spend a year of your life working on a book, release the examples and source for free to the web, only to have a slew of "that's nothing, I could do that in my sleep" comments from folks who don't bother to read the title (Pixel-Perfect) or other comments before posting. I'd just like folks to think before they post. I don't claim to have the best code, or the best way of approaching a task. I welcome *thoughtful* criticism.
@groundh0g The first thing you should know is the people who are commenting as such are probably not going to be your customer base as we already know how to code. Second, if your potential customers are coming here they probably don't want to see the author in a furry on his own videos.
@1dantheman100 agreed, pixel perfect hahaha, try doing it with an animated sprite as well, which frame do you have to check intersection on? static images are simplistic
@1dantheman100 for syntactic sugar and to make this a one liner just use: return sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))) <= diameter1 + diameter2;
i also wrote an engine similar to your one but mine is in visual basic. what is the way you did it ??? i used the pythagorean form thingy (- radius) pretty sick^^ xP nice vid 5*
@hrsitcom The source from my book, updated for XNA 3.x. is on my website (tripple-w-dot) codetopia (dot-com) slash cs. [Youtube doesn't like URLs in comments.]
It seems that you have the first part done, you've successfully detected a collision. Now you just need to do something about it, which can cause more problems. Good Luck!
I used circles for this demo because I'm not an artist. Even I can draw a circle. 8-)
The chapter explains how to detect whether or not two game objects have one or more pixels that occupy the same point on the screen.
Checking every pixel in every on-screen game object would be slow, so the code checks the bounding rectangles of the two objects first, and only performs the more expensive pixel-by-pixel scan when the rectangles overlap.
You could also do a quad tree collision where you create rectangles inside rectangles and continue dividing until rectangles are completely filled with pixels from the sprite and no transparent pixels. this saves alot of time because you can draw a big rectangle in the middle of a circle. which can turn 10x10 pixels for example into one check. in the end you only have to check each rectangle fully filled with the sprite's pixels on eachother.
Yep. Makes perfect sense. This is an example from a book for beginners, though. The bounding rectangle check is one of the simplest optimizations to explain.
And, given it's simplicity, it's not all that bad. The search within the 10x10 inner-rectangle you cite would stop when the first overlapping pixel is detected. Also note that only pixels within the overlapping rectangles are compared, not every pixel of each image.
I might describe the technique you mention in an article on my site.
can ny1 temme hw to appy...same collision for maze..im new to game programming...
krazeekrishna 3 months ago
did you use true pixel perfect detection or radial space? the video uses circles so it's difficult to know visually
xilefian 4 months ago
Not that hard this is 1 line of code
0ChrisMackle0 7 months ago
@0ChrisMackle0 Really? Enlighten us. What would that one line be?
groundh0g 7 months ago 4
@groundh0g hes talking about pythagorean theorum
Neptutron 2 months ago in playlist Visual Effects & Physics
@groundh0g you simply check the distance from the center of the circle to the centre of the other circle and see if its less than the radius of one plus the radius of the other. I'm not sure if that's what you've done, but that's all you've demonstrated. Circles are easy - if you want to demo your code, you need to use more abstract shapes.
joebharner1 2 months ago
@groundh0g for(int i = 0; i < spheres.size(); i++) if( (cursor.pos-spheres[i].pos).length() < spheres[i].radius ) hit(i)
imbusy111 1 month ago
@groundh0g If boundingCircle.Intersect(boundingCircle2)) collided = true;
Solti1485 3 weeks ago
@0ChrisMackle0 You are soo stupid!!!!!!!!!!!!!!!
orangegold1 7 months ago
@orangegold1
why idiot? because i didnt click show more i thought this was in C++
0ChrisMackle0 7 months ago
This has been flagged as spam show
what is the name of the book?
liveoles 9 months ago
This has been flagged as spam show
Just finished updating my java game and a zip with a jar and all the resources is online!! It's on my channel.... check it out
(youtube..dot..com) /watch?v=-3I_hUg06Dg
kylecowan990 9 months ago
Really? Circles is simple. I thought you would have more complex shapes. Simple collision.
if(sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))) <= diameter1 + diameter2){ return(true);
}
1dantheman100 11 months ago 13
@1dantheman100 you can also go even more advanced and take the current distance minus the 2 diameters and translate them accordingly.
1dantheman100 11 months ago
Really? The video is of an example program that's developed in a book that I wrote back in 2007.
The example taught the reader how to perform pixel-perfect collision detection. The sprites just happen to be circles. I can assure you that the algorithms support more complex shapes -- for example, it's used in a later chapters when the player blows up spaceships.
Congratulations on your mastery of determining the distance between two points, though. I'm sure that will come in handy.
groundh0g 11 months ago
@groundh0g I can't tell if you are using sarcasm or not, but this sounds interesting. Do you think you could help me with 3D collision? I'm not the best at it. I just assumed you found the distance between two points, due to the fact that they were circles. However, as we all know, assuming makes an ass out of u and ME. I have developed a couple games in my free time, both of which I tackled with a lack of experience. If you checked my vids, you can see how bad I was. Now, working on a new
1dantheman100 10 months ago
@groundh0g project, I've gotten a lot better. For instance, I have better terrain collision than I did with the Awakening Engine terrain. That's because I found a better method using rays. You probably had enough of my rambling by now. So could you please send me to some source, such as a tutorial? I would love to learn more about collision, 2D or 3D.
1dantheman100 10 months ago
Nicely handled.. .-.- Stop being a jerk, the guy didn't know.
orangegold1 7 months ago
@orangegold1 I'm not trying to be a jerk. It's just frustrating to spend a year of your life working on a book, release the examples and source for free to the web, only to have a slew of "that's nothing, I could do that in my sleep" comments from folks who don't bother to read the title (Pixel-Perfect) or other comments before posting. I'd just like folks to think before they post. I don't claim to have the best code, or the best way of approaching a task. I welcome *thoughtful* criticism.
groundh0g 7 months ago
@groundh0g The first thing you should know is the people who are commenting as such are probably not going to be your customer base as we already know how to code. Second, if your potential customers are coming here they probably don't want to see the author in a furry on his own videos.
jclaine 5 months ago
@orangegold1 But you're right in that I should have been less sarcastic in my response.
groundh0g 7 months ago
Comment removed
jclaine 5 months ago
@1dantheman100 agreed, pixel perfect hahaha, try doing it with an animated sprite as well, which frame do you have to check intersection on? static images are simplistic
roadtozion55 2 months ago
This has been flagged as spam show
@1dantheman100 for syntactic sugar and to make this a one liner just use: return sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))) <= diameter1 + diameter2;
Fiziks07 2 months ago
i also wrote an engine similar to your one but mine is in visual basic. what is the way you did it ??? i used the pythagorean form thingy (- radius) pretty sick^^ xP nice vid 5*
hrsitcom 1 year ago
@hrsitcom The source from my book, updated for XNA 3.x. is on my website (tripple-w-dot) codetopia (dot-com) slash cs. [Youtube doesn't like URLs in comments.]
groundh0g 1 year ago
hey this is really nice...i was hoping u could make a tutorial on collision detection? thank you :)
HowToDo92 1 year ago
nice, but for a pixel perfect detection demonstration, one would think you would chose some model other then a circle:)
avion85 1 year ago 6
@avion85 Agreed. I'm not much of an artist, though. :)
groundh0g 7 months ago
I forgot some dots, but yeah that's it.
zqewkl 2 years ago
The more I learn about AS3 for 2D games, the more I feel it's like using a bulldozer to make a sand castle...
For example, a pixel collision in AS2 was something like:
clip1.hitTest(clip2_x,clip2_y,true)
End of story.
Now with AS3 it's like 50 lines of code to make the same stupid shit.
zqewkl 2 years ago
Same here. That was, like, my favorite bit of code in the whole damn language.
EpicFailureFilms 2 years ago
I finaly found how to do it.
There's two kind of hitTest now, hitTestObject (the basic hitTest) and hitTestPoint, (the accurate one).
clip1.hitTestPoint(clip1.x,clip1.y,true)
AS3 games run faster, but take definitely way moretime to build.
zqewkl 2 years ago
damn, it's clip2 instead of clip1 in the braces.
Nevermind.
zqewkl 2 years ago
What's unusual in this?
tomaszq120 2 years ago
where is the tutorial?
mauletlliure 2 years ago
Does your method provide a collision depth as a result?
Nequame 2 years ago
Nope, but since the objects are all circles for this demo, you can use their relative locations to determine the collision depth.
This video showcases one of the examples from my book -- XNA Game Studio Express: Developing Games for Windows and the Xbox 360.
groundh0g 2 years ago
It seems that you have the first part done, you've successfully detected a collision. Now you just need to do something about it, which can cause more problems. Good Luck!
kevin92620 3 years ago
this is actualy pretty easy since you can just check if a circle is within the radius of the one you're moving. ;)
vincentpol 4 years ago
True. If your game only contains circles.
I used circles for this demo because I'm not an artist. Even I can draw a circle. 8-)
The chapter explains how to detect whether or not two game objects have one or more pixels that occupy the same point on the screen.
Checking every pixel in every on-screen game object would be slow, so the code checks the bounding rectangles of the two objects first, and only performs the more expensive pixel-by-pixel scan when the rectangles overlap.
groundh0g 4 years ago
You could also do a quad tree collision where you create rectangles inside rectangles and continue dividing until rectangles are completely filled with pixels from the sprite and no transparent pixels. this saves alot of time because you can draw a big rectangle in the middle of a circle. which can turn 10x10 pixels for example into one check. in the end you only have to check each rectangle fully filled with the sprite's pixels on eachother.
hope I make some sense :P
vincentpol 4 years ago
Yep. Makes perfect sense. This is an example from a book for beginners, though. The bounding rectangle check is one of the simplest optimizations to explain.
And, given it's simplicity, it's not all that bad. The search within the 10x10 inner-rectangle you cite would stop when the first overlapping pixel is detected. Also note that only pixels within the overlapping rectangles are compared, not every pixel of each image.
I might describe the technique you mention in an article on my site.
groundh0g 4 years ago
Nice.
whothehellisthat 4 years ago