OK, think this...
You start with a paddle, with this properties:
Left Position = 0
Width = 100
Normally the angle goes from right (0 degrees),
to top (90 degrees) and finally the left (180 degrees).
Code:
90 degrees
.-"""-.
.` `.
/ \
180 ------------- 0 degrees
If you get the angle in reverse (left=0, middle=90, right=180)
then you have a easy equation:
Angle = (RelativeBallHitsPossition * MaxAngle) / (PaddleWidth);
To get the real angle, only do this:
(you can do it in the previous equation)
Angle = MaxAngle - Angle;
NOTE: Probably you need the angle in RADIANS. In this
case, the MaxAngle value is 2*PI, else the value
is 180 degrees.
Uhm, I forgot it. The Paddle can change it position.
You need the "BallHits" position relative to the
origin of the paddle: then do this:
RelativeBallHitsPossition = BallHitsPossition - PaddleLeft;
TIP: You can use integer operations to improve the performance.
Use div better than / for example.
Bookmarks