Skip to main content
gamedev.net
🔒 Locked

Multiple Rectangle Colition Detection

Started by jamescox3k Dec 11, 2002 at 1:14 PM 1 replies 650+ views
Original Post
jamescox3k
jamescox3k
If I had an array of rectangles that all had a movment perframe value (i, j) how would I beable to move the so that when they collide they bonce of each other?
JC
rmsgrey
rmsgrey
Depends what level of realism you want in your bouncing. Simplest is just to swap movements of the two rectangles. You could check for whether they''re meeting on horizontal or vertical edges and swap the other co-ordinate of the movement.

If you want to give you rectangles different inertial masses then rather than swapping velocities, you''d swap momenta:

(i1,j1) collides with (i2,j2) on a vertical edge:

(i2*m2/m1,j1) and (i1*m1/m2,j2) are the result, where m1, m2 are masses (in the case of constant density, ratio of masses is the same as the ratio of areas)

If you want to be completely relistic, you''d have to consider the effects of angular momentum (collision off center starts rectangles spinning), friction (between rectangles and elasticity. You can probably ignore gravity
jamescox3k
jamescox3k
Thanks, Thing is i''m working on a platform game like mario. And I have a rather heavy colition detection algorithum (that i made up my self (which probably dosn''t help)) and I''d like to make it simpler.

ne way when i finnish it it will be up on the web with souce for any one who whants it!
JC

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.