Page 2 of 2 FirstFirst 12
Results 41 to 43 of 43

Thread: Collision Detection - Need optimization/faster method

  1. #41
    New Member
    Join Date
    Nov 2006
    Posts
    10

    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.

  2. #42
    Hyperactive Member
    Join Date
    Aug 2006
    Posts
    367

    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..

  3. #43
    Member
    Join Date
    Jan 2004
    Posts
    37

    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.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width