Advertisement

easy game help

Started by April 13, 2000 08:19 PM
5 comments, last by OoMMMoO 24 years, 6 months ago
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
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
Advertisement
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.
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
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?
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
aig
Advertisement
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
aig

This topic is closed to new replies.

Advertisement