PDA

View Full Version : Breakout angles



Johnny2x4
29th May 2008, 12:44 PM
does anyone know the formula for the anglesat which the ball is supposed to bounce when it hits the paddle?

ShadowGandalf
29th May 2008, 01:07 PM
I assume it's pretty basic. If the paddle is stationary, then the angle of incidence is the same as the angle of reflection. If the paddle is moving at a given speed v, then you have the reflection vector added to the vector of the paddle.

or something like that.

scyld
29th May 2008, 01:18 PM
Well I'm not sure if you're right or wrong SG, but typically there is also an effect if the ball hits near one of the paddle's edges to simulate bouncing off a "rounded corner" or something.

ShadowGandalf
29th May 2008, 01:55 PM
Oh. Is there? I haven't played any version of the game in a while. I'm sure someone who actually likes physics can work out the details.

Shane-
29th May 2008, 02:32 PM
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_21493997.html

Edit the code to include:

function GameLoop(){
if(ballY < 0)
angle = 180 - angle;
else if(ballX < 0 || ballX > 485)
angle *= -1;
(Which is at the very bottom of the page)



Shane

Johnny2x4
29th May 2008, 03:37 PM
thank you Shane.

But I probably should've mentioned that I was writing it in java so I'll have to convert it somehow lol.

scyld
29th May 2008, 08:17 PM
Unless I'm terribly mistaken, the code quoted just models the ball bouncing off the side walls and bottom of the screen. It doesn't model the ball bouncing off the paddle, though I'm sure that code is somewhere else on the linked page.

Shane-
29th May 2008, 08:29 PM
Unless I'm terribly mistaken, the code quoted just models the ball bouncing off the side walls and bottom of the screen. It doesn't model the ball bouncing off the paddle, though I'm sure that code is somewhere else on the linked page.

Your correct

The problem the guy was having was the ball would just bounce off the paddle(Once), And go sky high (Off the screen and not come back).

As you'v said, The whole code is on the website, He asked how to fix it, And the replys at the very bottom of the page, Wanted to highlight it to ensure it was seen as most people wouldnt scroll that far down

As for the question, It was if anyone knew the formula for the angles, which is also listed, Its about all i found on google regarding the subject

John Galt, Wouldnt you be able to edit what you have already (Wrote in java), And include the angels that are listed on experts-exchange.com?


Shane

Johnny2x4
30th May 2008, 06:26 PM
yes but I made the ball move with a x-speed and y-speed, not an angle because I didn't know how to do that but I'll look in the API and if I can't find anything I'll come up with some formula.

(oh and the problem was just with the angling of the paddle not the screen itself)

Carnage
31st May 2008, 06:46 AM
http://sourceforge.net/search/?type_of_search=soft&type_of_search=soft&words=breakout

Plenty of example code there for you.

Also if you have the X+y you can find the angle using trig. tan(x/y) if i remember right.

scyld
31st May 2008, 04:09 PM
yes but I made the ball move with a x-speed and y-speed, not an angle because I didn't know how to do that but I'll look in the API and if I can't find anything I'll come up with some formula.

(oh and the problem was just with the angling of the paddle not the screen itself)

If you don't know simple trigonometry, which allows you to go between individual x and y components to angles and vice-versa, then programming even any extremely basic physics models like this will be impossible.


Also if you have the X+y you can find the angle using trig. tan(x/y) if i remember right.

Yes, that's right.