1 Attachment(s)
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.
Re: collision detection, problem with my code?
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:
For i = 0 To 999999
Rect(i).Left = boxx(i)
Rect(i).Right = Rect(i).Left + 24
Rect(i).Top = boxy(i)
Rect(i).Bottom = Rect(i).Top + 24
Next i
from form_loadup
and under game_update, before 'godothecrap', put
VB Code:
For i = 0 To numboxes
Rect(i).Left = boxx(i)
Rect(i).Right = Rect(i).Left + 24
Rect(i).Top = boxy(i)
Rect(i).Bottom = Rect(i).Top + 24
Next i
Goodluck =)
1 Attachment(s)
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.