At 2/25/08 12:59 AM, 23450 wrote:
Here is a small picture of how its all done. After the object hits the wall, you find the normal line using glaiels code. After you have this code, you take the difference between the normal angle and the incomming angle, and use that to get the outgoing angle. The outgoing angle is the same distance away from the normal line as the incomming angle. So angle 1 is equal to angle 2, in relation to the normal.
you don't have to deal with angles once you have the normal, that only complicates things.
given the normal N, and the incident vector V, the reflected vector R is given by R = V-2N(N.V) where . denotes the dot product. if R,V,N are objects with x and y members, this suffices.
var dot:Number = -2*(N.x*V.x+N.y*V.y);
R.x = V.x + dot*N.x;
R.y = V.y + dot*N.y;