Re: OT: would anyone happen to know how to calculate bouncing a ball off an angled box?
Neglecting corner hits;
1) You want to know the relative angles between wall and ball. All arithmetic is modulo 360 degrees. (359 + 1 = 0)
2) We can rotate the coordinates by minus the wall angle. This makes the wall look like zero, and the ball will be ball_angle - wall_angle.
You want to reflect in the plane of the wall.
Taking 90 degrees off it, then taking the negative, and adding the 90 degrees back.
85-90 =-5, -5 -> +5, 5+90 = 95 (check)
224 -90 = 134, 134 -> -134 (or 226), 226+90 = 316 (check)
3) Restore the original coordinates by adding back the wall's angle.
So:
NEW_ANGLE = ((((OLD_ANGLE-90-WALL_ANGLE)*-1)+90+WALL_ANGLE) +360) % 360
Where % = modulo operator in whatever programming language you use.
360 is added before the modulo operation because to ensure the resulting value is positive. (Some programming Languages deal with modulo of negative numbers differently)
-----
For Corner Hits:
The effective plane that the ball is bouncing off of is perpendicular to the line connecting the center of the ball to the corner.
__________________
Things you want:
|