iDevGames Forums
2D deflection - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: 2D deflection (/thread-5649.html)



2D deflection - whogben - Apr 11, 2005 12:07 PM

I am talking about sphere on sphere deflection, I have x1, y1, x2, y2 (positions for each sphere), I have r1, r2 (radius for each) and vx1, vy1, vx2, vy2 (x and y velocities of each) and m1, m2 (masses for each)

First I check to see if they intersect (r1+r2 > distance_between), but I cant seem to wrap my head around how to deflect them with each other. They are hitting each other at some angle, which I could get from the slope of the line between them, no problem, but could someone write some psuedo-code for this kind of deflection, I cant seem to get it. Thanks in advance, Will.


2D deflection - kelvin - Apr 11, 2005 03:13 PM

First back up the spheres until they are non-intersecting or close to. Then draw a line between the centers. Dot with each sphere's velocity vector to find the force component you need to sum and reflect. Update your velocity vectors and the move by the time you backed up.

I did all this math a long time ago but I don't have any code to show for it. Sorry. There are simpler/faster/less accurate ways of doing things, so don't take my word for it.