Vaecrius wrote:someone else will have to reply with how to get the angle (which I'd like to know as well).
Well, once you have the line, you can access the line's
delta vector and get the vector perpendicular to it:
Code: Select all
Vector2 perpVec = (-line.delta.y, line.delta.x).unit();
Once you've got that, you can use the formula
r = d - 2(d dot n)n (where n must be normalised; this is the point of the .unit() call) to generate the reflected vector:
Code: Select all
Vector2 reflected = vel.xy - 2 * (vel.xy dot perpVec) * perpVec;
to get the Vector2 of reflection (you can upgrade this to 3d by making
reflected a Vector3, removing all calls to
.xy in the formula, and constructing a 3d
perpVec (where Z will always be 0 since a linedef cannot be sloped)). Then, if you want the angle of reflection:
Code: Select all
double rAngle = atan2(reflected.y, reflected.x);
Provided all my maths is correct, that should work.