Quote:Original post by lack the hack
i'm only comparing their x-axis values(it's a 2D game)so i thought it would be possible for their x-axis to be exactly the same due to the x-axis vertices moving across the screen
is my type of collision detection unheard of, or do some people do this kind of method? (sorry to be a little off topic)
If you're only comparing the x axis values, and only when they are equal, then it's not going to work. For the sake of argument, let's assume that there's a chance that they'll have equal x values, which is just not going to happen with floating point values.
Using this criteria, the following boxes would be flagged as colliding
+------+ | | | | +------+ +-----------+ | | | | +-----------+
Also, let's assume for the sake of argument that you were using integers for coordinates, so that the x values could be equal.
Let's say box two is at the right of the screen, and moving to the left, at a speed of 2 units per frame. Box one, is stationary.
Let's step through the code and see what happens
As you can see, because box two was travelling at two units per frame, which
meant that it went right through the other box without their x values ever being equal. Not only that, but you'll also notice, that their x values were not identical when they started colliding.
If you're interested in learning about things like collision detection for 2D games, then I highly recommend the book "Tricks of the windows game programming gurus" by Andre Lamothe. It explains these things in a way that's really easy to understand, and the book is also a good reference for many other subjects as well.
[Edited by - Oxyacetylene on September 23, 2005 9:15:27 PM]