# Thread: Need help with Reflecting Angles!

1. ## Need help with Reflecting Angles!

i've did a pong game but the problem is my ball moves in fixed angles (always 45 degrees up or down) how can i fix this?!? i mean the ball moves by ball.x++ and ball.y++ and not by angles!

i have a struct for the ball so i know i have to add ' float angle ' to the array but how do i determine the launch angle of the ball from the paddle hit?!? please can someone give me the equasion?

(heard it was something with trigonometrical functions)

thx a bunch 2. ## ~

ball.x += sin (ball_angle);
ball.y += cos (ball_angle);

(this could be wrong, I'm not thinking very strongly right now)

Remember that ball_angle must be in radians. 3. It will also bounce off a wall/paddle at the same angle which it hit...flipped over the normal.

\|/

Where the left is the path from where the ball came, the underline is the wall, the vertical line is the normal of the wall (right angle to wall) and the right hand slash is the angle at which it will leave. For computing the movement from the angles...depending on which way ball_angle points when it equals 0, you'll either want to do what is stated above, or:

ball.x += cos(ball_angle);
ball.y += sin(ball_angle); 4. in case you didn't understand what black said the angle formed between the wall and the ball is the same when it is coming towards the wall and exiting the wall

the red angles are the same in this picture 5. What do you think, guys? Should I write a short tutorial about the angle at which a ball bounces off a wall? 6. why not?  7. and how do i change the ball's angle according to the hit?!? 8. The middle angle in Silvercord's drawing (not labeled) is equal to 180-2*angleofimpact. Take that knowledge and apply it to changing the angle. Popular pages Recent additions 