ball, paddle and degrees!

Non-platform specific questions.

ball, paddle and degrees!

Postby sonicfire » Fri Nov 11, 2011 10:15 am

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! :)
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Re: ball, paddle and degrees!

Postby skydereign » Fri Nov 11, 2011 11:08 am

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);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: ball, paddle and degrees!

Postby sonicfire » Sat Nov 12, 2011 10:26 am

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?
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

Re: ball, paddle and degrees!

Postby skydereign » Sat Nov 12, 2011 12:53 pm

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);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: ball, paddle and degrees!

Postby sonicfire » Sat Nov 12, 2011 3:09 pm

Amazing. Thank you! Point given :)
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest