Hi
Can someone point me in the right direction of the maths behind sending a ball at a certain angle and then it bouncing off (like in the Breakout games).
Thanks.
Hi
Can someone point me in the right direction of the maths behind sending a ball at a certain angle and then it bouncing off (like in the Breakout games).
Thanks.
Its a little more involved than this, but as a starting point:
Give the moving object maxSpeed and x & y velocities. Figure out if the moving object is going to hit the ‘wall’ (line) & get the point of impact. Use trigonometry on the x & y velocities to figure out the angle that its approaching the line, then figure out the angle it will bounce off it. Use this new angle to give the object a new x & y velocity.
To simplify the angle calculations, make all of your polygons which comprise your obstacles/walls list their points in the same anti-clockwise direction.
I hope that helped,
Keith
Generally, get the angle of impact and reflect in the same angle.
If you only have vertical and horizontal bouncing like Breakout or Pong, inverting the x or y velocity does it.
-JAW
Except that thats not how breakout does it. In breakout, the closer to the edge of the bat the sharper the angle the ball bounces off at. IIRC the input angle isn’t taken into account at all.
Yea thats how its done in classic breakout games. However, in most modern breakouts the bumper is arced and the ball is bounced off in a realistic manner… its sorta more intuitive to use.
Yeah but it then results in a slightly different gameplay which is, in my opinion, less powerful (yet simpler).