SFML community forums

Help => General => Topic started by: TheBaldPanda on October 03, 2013, 04:01:28 am

Title: Pong- How would I make the ball bounce of at different angles?
Post by: TheBaldPanda on October 03, 2013, 04:01:28 am
Hey. I am making my first game, and so far handled everything else but this. The two paddles just bounce the ball in a straight line, and that isn't fun at all. I am wondering, how would I make it bounce off at an angle? PLEASE provided example code if possible   :D
Title: Re: Pong- How would I make the ball bounce of at different angles?
Post by: Ixrec on October 03, 2013, 04:15:59 am
We're not going to write your code for you.  If you can't implement stuff like this yourself, you'll just have to post another topic every time you want to add a feature.

In this case, since the paddle angle is stationary, just look at the current velocity of the ball, compute the angle from the horizontal, take the opposite angle (you'll probably want a more complicated bouncing rule eventually) and compute the velocity from that.

If you're asking for how to go from a velocity vector to an angle, that's simple trigonometry, and we can answer questions like that, but you'll have to give a very precise question so we don't just bombard you with formulas you already know and don't need.  If you have no idea what I'm talking about, you're probably better off googling some crash courses on stuff like trigonometry because you will need to know that to implement any decent 2D physics.
Title: Re: Pong- How would I make the ball bounce of at different angles?
Post by: eXpl0it3r on October 03, 2013, 04:36:53 am
There's also the example directory of SFML's source code that features a full Pong clone. You can take a look there, it's really quite simple. ;)