Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Pong- How would I make the ball bounce of at different angles?  (Read 2079 times)

0 Members and 1 Guest are viewing this topic.

TheBaldPanda

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
Pong- How would I make the ball bounce of at different angles?
« 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

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Pong- How would I make the ball bounce of at different angles?
« Reply #1 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.
« Last Edit: October 03, 2013, 04:17:37 am by Ixrec »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Pong- How would I make the ball bounce of at different angles?
« Reply #2 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything