Page 1 of 1

ball, paddle and degrees!

PostPosted: Fri Nov 11, 2011 10:15 am
by sonicfire
Image

Please have a look at the picture :)
For my breakout-game i want the ball to bounce in these directions
and ignoring his origin angle.

so when e.g. the ball goes down straight (angle=270 in GE) and hits the
paddle like in the right corner almost at the edge, it goes up with angle=45.

hope i explained my problem well :oops:
can anybody help me here with the maths?

much appreciated - thanks! :)

Re: ball, paddle and degrees!

PostPosted: Fri Nov 11, 2011 11:08 am
by skydereign
So you want it to only bounce at 45, 90, and 135 degree angles? Your picture is a tad confusing, as when it hits the +45 section, it moves at a normal reflective bounce's angle, instead of a 45. And so you know, you can use collide.x to determine which part of the paddle you are colliding with, since if you know that the paddle's x is 0, and the ball's x is 0, then if the difference between the two was 45, then it must be the right side of the paddle, and -45 for the left.

One question though, if the ball is moving at lets say a 300 degree angle, and hits the left side of the paddle, does it still bounce back at a 135 degree angle? If so, then I understood you correctly, and you can do something like this.
paddle -> Collision with Ball -> Script Editor
Code: Select all
int dir = round(((x+width/2)-collide.x)/(width/2));
// above should set dir to 0 if on the far right of the paddle, 1 if in the center, and 2 if on the left
collide.angle=45*(dir+1);

Re: ball, paddle and degrees!

PostPosted: Sat Nov 12, 2011 10:26 am
by sonicfire
great! thanks so much :) almost exactly what i wanted to achieve.
the only thing is, there should be something "in between" not only bouncing to the left,right or top.
i was a bit unclear with my description, yes :)

how would i go about changing this? can you help me once again please?

Re: ball, paddle and degrees!

PostPosted: Sat Nov 12, 2011 12:53 pm
by skydereign
You can break it up into smaller sections, so say you have 5 angles (4 divisions) instead of the 3 (2 divisions).
Code: Select all
int num_divisions = 4;
int dir = round( num_divisions*(((x+width/2)-collide.x)/width));
collide.angle=45+dir*(90.0/num_divisions);

Re: ball, paddle and degrees!

PostPosted: Sat Nov 12, 2011 3:09 pm
by sonicfire
Amazing. Thank you! Point given :)