Page 1 of 1

rotation and angle problem

PostPosted: Wed Jun 04, 2008 2:21 pm
by JayInACob
im trying to make a pong clone, but in which the player can rotate the board thing to get better shots.

Anyway, i need to get it so the opponent flipper adjusts its angle so it always hits the ball in a specific direction, or better, to hit a specific point on my side of the area.

Any help would be greatly appreciated!! :D

Re: rotation and angle problem

PostPosted: Sat Jun 07, 2008 5:01 am
by DST
Cheat! That's how Capcom does it!

Just make him hit it there! No physical response, no fairness. Make him to what you want!

Make it like this perhaps:

ball>collision>enemyflipper
Code: Select all
ball.angle=direction(x, y, player.x, player.y+rand(100)-50);


Now the ball with move toward player one +- up to 50 degrees in either direction!
You can alter this in any way you want, and of course this might be a problem if player one is on the edge of the screen, as the ball might be hit off the top or bottom.

So add adjustments;

Code: Select all
if (player1.y>-140 && player.y <140){do what i just said}
else if (player 1.y<-140 || player1.y>140){ball.angle=0;}


Now if the player is at the top or bottom, the enemy will hit it straight down the middle!

This is all of course, assuming that the playfield is in a normal horizontal state.

If it rotates, perhaps you can adjust the angle like this:
Code: Select all
ball.angle=direction(x, y, player.x, player.y)+(rand100)-50;


Now the offset will simply be on either angle side of player 1, regardless of whether the playfield is horizontal or vertical.