Re: Collision Detection - Need optimization/faster method
Ohh... ok i don't know where i got it from but the one i made is still alot faster then all
of yours it's not circular it's daimond shaped and when i was younger i used it a lot in
all my 2d games. i trade triggernum5 idea but it was still slower then mine and
Abs() are not nearly as slow as using high level code.
Re: Collision Detection - Need optimization/faster method
No, distance is meant to be the shortest distance (as the crow flies, along a straight line).. Its vital that this be accurate to his application.. The correct method measures the length of a triangle's hypotenuese, yours adds the lengths of the other 2 sides.. Its like the field example I made, if you need to get to the kittycorner side of a 1sq mi field you can either walk 2 miles around the perimeter (as your calculation implies) or 1.41 miles diagonally across.. Your equation is valid when dealing with definate pathways.. And in a game where right/left/up/down are the only possible movements (Like old square based games like Zelda) then both of the eq'ns yield the same result..
Re: Collision Detection - Need optimization/faster method
You're doing an expensive collision detection, but that's not necessary for all objects. Try doing a cheaper detection first, and only a more expensive one once you are sure the two objects are actually close to eachother. This will save a bunch of time.
You can fit a circle with radius R in a square with dimension of 2R.
Checking if two squares intersect is cheaper than checking with circles, because with squares you only need to add and subtract.
If two squares don't intersect, circles won't either, if they do intersect, the circles might intersect, so then you would have to do your expensive detection.
Your detection should look like:
if ((abs(a.x - b.x) - a.r - b.r) < 0) and (abs(a.y - b.y) - a.r - b.r < 0)) then
'check for circle collision
end if
Also try to find other ways reducing the amount of objects you have to check, like only objects that are in the same area, only objects that can interact with eachother, etc.