Results 1 to 40 of 43

Thread: Collision Detection - Need optimization/faster method

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    108

    Collision Detection - Need optimization/faster method

    Hey everyone, ive been working on a small space/rpg type game for the last week or so, and ive come to a pretty big problem. In my game i need to check for collisions between players/projectiles and player/pickups. the problem is there are (at least in the small demonstration version ive made so far) 999 players, 999 projectiles, and 999 pickups which need to be checked. the total number of loops alone in my collision detection sub is 998001 loops, with 2 fairly complex calculations per loop. At its current status, it takes about 2.5 seconds just to go through one loop on an Athlon 64 3700+ 2.2ghz cpu.

    I need ideas/examples on a MUCH faster/more efficient way of checking for collisions. I check the distance between the objects in my game and subtract each radius because most of the objects in the game are circular, and those that arent are small enough to be considered so. so distance is an easy enough way of checking for collisions in this game at least.

    here is my current sub for collision detection

    VB Code:
    1. Public Sub check_for_collisions()
    2. 'check for collissions between player/projectile and player/pickup
    3.     Dim i As Integer
    4.     Dim r As Integer
    5.     Dim tempdist1 As Single
    6.    
    7.     For i = 0 To 999
    8.         For r = 0 To 999
    9.             'check player/projectiles
    10.             tempdist1 = distance(player(i).x, player(i).y, projectile(r).x, projectile(r).y) - (player(i).radius + projectile(r).radius)
    11.                 If tempdist1 <= 0 Then
    12.                     collision_player_projectile i, r
    13.                 End If
    14.             'check player/pickups
    15.             tempdist1 = distance(player(i).x, player(i).y, pickup(r).x, pickup(r).y) - (player(i).radius + pickup(r).radius)
    16.                 If tempdist1 <= 0 Then
    17.                     collision_player_pickup i, r
    18.                 End If
    19.         Next r
    20.     Next i
    21. End Sub

    Im thinking i may just have to cut back to a max of 99 or so entities of each (player, station, projectiles and pickups even tho only projectiles and pickups are used in this sub (as well as players)) but i wanted to make this a very large scale game, with almost so many things to explore you would never be at the same place twice.

    So, if anyone could help me that would be more than greatly appreciated.

    Id rather not give the whole source to the game, but attached is a compiled version of what i have so far without collision detection enabled (so its actually playable XD). All that happens right now in the version attached is 999 of each type of entity is spawned, and fly in random directions (except for AI player (pirates, traders, police), they just have a simple AI which makes them follow you (or try to) around.

    PS. In order to make it run, you need to put PBGL.dll in your c:\windows\system32 folder and then in start>run or command prompt type "regsvr32 c:\windows\system32\pbgl.dll". PBGL.dll is a "Picture Box Graphics Library" that i wrote to make it easier to do things with picture boxes like using transparent bitblt and other pretty simple drawing operations. Oh, and as i mention that i think it should be stated that all things in the game are rendered with bitblt.

    PSS: when running the game please tell me the framerate you get (in the lower right hand corner of the window) and your pc specs (processor at least). I need to make sure my code to control the framerate is working right. It should be a constant 32, if it goes below 32 dont worry, its pretty demanding (yes, i need to work on it a bit more) but if it goes over 32 let me know because that would be another bug to fix...
    Attached Files Attached Files

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