Need help with Reflecting Angles!

This is a discussion on Need help with Reflecting Angles! within the Game Programming forums, part of the General Programming Boards category; i've did a pong game but the problem is my ball moves in fixed angles (always 45 degrees up or ...

  1. #1
    SRM
    SRM is offline
    Registered User
    Join Date
    Apr 2003
    Posts
    4

    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. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    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.
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    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);
    Away.

  4. #4
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    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
    Attached Images Attached Images  

  5. #5
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    What do you think, guys? Should I write a short tutorial about the angle at which a ball bounces off a wall?
    Away.

  6. #6
    SRM
    SRM is offline
    Registered User
    Join Date
    Apr 2003
    Posts
    4
    why not?

  7. #7
    SRM
    SRM is offline
    Registered User
    Join Date
    Apr 2003
    Posts
    4
    and how do i change the ball's angle according to the hit?!?

  8. #8
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    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.
    Away.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to C please help
    By zidangus in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2008, 09:27 AM
  2. getting distance from angles
    By HermitCrab in forum C++ Programming
    Replies: 5
    Last Post: 06-08-2007, 07:26 PM
  3. Help with Programming Assignment
    By JHaney in forum C++ Programming
    Replies: 18
    Last Post: 11-08-2005, 02:45 AM
  4. how can i draw angles by lines
    By NEO_4583 in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2003, 07:40 PM
  5. bounce angles
    By canine in forum Windows Programming
    Replies: 1
    Last Post: 09-04-2002, 09:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21