Results 1 to 4 of 4

Thread: collision detection, problem with my code?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    108

    collision detection, problem with my code?

    well, im working with my box spawner program again, trying to get it to detect collisions so the boxes will stack and bounce off each other etc, and im having a slight problem. after there is more than 1 box spawned, they just stop moving, like they are endlessly colliding causing their speed to slow to a stop as in the code that executes when there is a collision, and this all occurs when there is more than 1 box, it doesnt matter if they are colliding or not. the collision detection code works i know, but i think there is either a problem with my loops going thru checking each box for a collision with every other box, or in the form_load where i define the rect's of each box. can someone help?

    code attached.
    Attached Files Attached Files

  2. #2

  3. #3
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: collision detection, problem with my code?

    The whole error is occuring at the line
    Collided = IntersectRect(ResultRect, Rect(r), Rect(p))

    You haven't defined the rectangles Rect(r) and Rect(p). You defined them in form_loadup, where boxx and boxy were not yet spawned.

    remove the code
    VB Code:
    1. For i = 0 To 999999
    2.     Rect(i).Left = boxx(i)
    3.     Rect(i).Right = Rect(i).Left + 24
    4.     Rect(i).Top = boxy(i)
    5.     Rect(i).Bottom = Rect(i).Top + 24
    6. Next i
    from form_loadup

    and under game_update, before 'godothecrap', put
    VB Code:
    1. For i = 0 To numboxes
    2.     Rect(i).Left = boxx(i)
    3.     Rect(i).Right = Rect(i).Left + 24
    4.     Rect(i).Top = boxy(i)
    5.     Rect(i).Bottom = Rect(i).Top + 24
    6. Next i

    Goodluck =)

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    108

    Re: collision detection, problem with my code?

    ok thanks, that code works for collision detection but ive tried several different ways to make the boxes stack, but ive always run into the boxes flipping out and flying everwhere rather than looking even the slightest bit realistic. if you could spare some time, could you help me figure out a way to make them realistically react to each other when they collide?

    also if you are wondering why theres so much stuff commented under the physics code its because i changed the code from my noobish leftspeed/rightspeed stuff to a usual xspeed.
    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