Jump to content
  • Advertisement

Archived

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

OoMMMoO

easy game help

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!