#### Archived

This topic is now archived and is closed to further replies.

# easy game help

This topic is 7124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Im new to game programming and am working on a pong game and was wondering how to figure out which angle the ball bounces back at when hitting a wall or board? please help

##### Share on other sites
Doesnt the ball always bounce back at a mirrored angle on the 90 degree angle. suppose it bounced at a 10 degree angle, that means it would bounce back at a 170 degree angle. i'm not sure about any formulas for that but i am sure someone else has some here that they would share.

I suppose by this you mean that the wall/board is at the 0 degree point and that perpendicular to that is the 90 degree point?

I just came up with a formula (if thats what you want to call it). Just take the angle that the ball (or whatever it is) is bouncing at and subtract it from 180.

Suppose it was bouncing at a 35 degree angle. just:

180-35=145. so that means the ball would bounce out at an angle of 135 degrees. here is a very simple formula if you haven't figured it out yet:

180-attackangle=bounceangle

or something of the sort. i think that should do the trick.

- Moe -

Edited by - Moe on 4/13/00 8:41:59 PM

##### Share on other sites
Moe''s idea won''t work. If you did it that way, the ball would only bounce in 4 different angles. If, for example, the ball started at a 30 degree angle, bouncing it around would only give 30, 150, 210, and 330 degree trajectories.

I would implement Moe''s idea for any static bumpers, but use the movement of the player''s pads to influence the ricochet angle.

##### Share on other sites
There is a simpler method, which I think most games like yours use. If the ball hits a vertical wall, change the sign of the x velocity. If it hits a horizontal wall, change the sign of the y velocity. I''m not sure how true these results are to physics, but what the player sees is very convincing.

Wes Henwood

##### Share on other sites
since we''re on the subject, you''ve all seen games where when the ball hits the paddle, it bounces back at an angle relative to where it hit on the paddle, i.e if it hits the edges, it bounces back at lower angle than if it hits the middle of the paddle. how would you do that?

##### Share on other sites
Wes''s approach is the simplest (and I think the one to go with).

Zipster, to put "English" on the ball, you could do it a couple of ways. The easiest (and most common) is to set the x velocity to reflect distance of the collision from center of the paddle (as well as flipping the sign of the y vel). In other words, collision in the exact center of the paddle sets x vel to 0 (ie. it will bounce straight up), while the further to the right of center it hits, the more positive you set the x vel, and the further to the left of center the collision, the more negative you set the x vel.

Another less-used approached is to take into account how fast the paddle is currently moving. In other words, if the paddle is still, simply flip the sign of the y vel. The faster the paddle is moving to the right during collision the more you inc the x vel as well as changing the sign of y. The faster the paddle is moving to the left, the more you dec the x vel. Vice versa of the left and right can be used for different effects as well.

With both of the above, you have to play with the amounts of incrementing and decrementing until you get a bounce response you like. The two methods above can also be combined for some very interesting (but somewhat complicated) bounce responses.

aig

##### Share on other sites
As a fan of pong-type games, I should mention that although the simple sign-changing approach works great, you should build something into your game to prevent the ball getting stuck in a loop - very annoying for the player.

A way around this is to keep track of the number of collisions since the last brick was destroyed, and when the number reaches a high number (I guess 50 would be a good estimate), assume the ball is stuck in a loop and do something to break the pattern (eg. muck up the x and/or y velocities, remove one of the unbreakable bricks causing the loop, let the player reshoot the ball from the bottom, give a free ride to the next level, etc.)

aig

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 33
• 9
• 16
• 22