1 Reply Latest reply on Mar 3, 2008 7:46 AM by Rothrock

    Collision detection technique

      I have done a lot of reading of collision detection. From what Ive gathered Ive learned that the hittest isnt the greatest thing, although in some situations its easier. Math is the superior way. The way in my mind that collision detection works is that you have lets say 5 orange objects and 5 blue. To check to see that their hitting you would need to check the position of 1st orange with 1st blue then Or 1 with B 2. and so on. For a total of 25. Then its better idea to get rid of tests that have already happened so that way it does a little fewer than 25 checks. So what I believe you can do is get that down to 5+4+3+2+1 = 15 checks lets say everyframe. I have never heard of a better way then that until I came up with this idea that I believe can get it down to ten. I might just be crazy and stupid or just have no idea what the hell Im talking about but I believe this is a much better method.

      I have been working on my game for quite some time now. It involves a bomb falling from the top of the screen at a set x value and then a bullet from the gun at the bottom of the screen. What if for the collision detection I had it

      Check one bomb when it was created and see if should hit any of the bullets
      If so calculate the distance and then the time
      Add which bomb, the time, its pos at time of collision to an array
      When a bullet is create see if it should hit a bomb
      Do the same for it except same array and which bullet

      Then have a function that orders the objects by the time that they should colide and also when the time comes it does the process of (in my case) having a explosion at that position and getting rid of the correct bullet and bomb.
      Now Ive done the math and it seems to come out to much less checks. Correct me if Im wrong.
      25 fps = each frame is 40ms
      bomb is created every 300ms
      bullet is created every 100ms
      Lets say I have 20 bombs and 20 bullets on the screen at one point.
      with the other method that would be
      210 checks every 40ms or 400 checks every 40ms
      With my way
      20 checks every 100ms + 20 checks every 300 ms
      So 80 checks every 300 ms or 10.6 checks every 40ms
      This would be much less calculations for the computer right.

      I thought of this a while ago and have thought it through in my head many times and it seems to make sense to me. Is it even possible? if so would it be worth the extra code? Or am I just missing something obvious and is this really stupid to anyone that actually knows what their doing. I just wanted to throw this idea out there and see what people who unlike me know flash think of it. Any thoughts or comments would be much appreciated.