Quote:
Originally Posted by Kritjon
Just give the paddle a maximum speed.
ActionScript Code:
const PADDLE_SPEED = 10;
function ai(event:Event):void {
if ((Math.abs(paddle.y - ball.y)) < PADDLE_SPEED) {
paddle.y = ball.y;
} else if (paddle.y < ball.y) {
paddle.y += PADDLE_SPEED;
} else {
paddle.y -= PADDLE_SPEED;
}
}
|
alright you lead me to the right track track with the if(paddle.y < ball.y) and if(paddle.y > ball.y) which resulted in the finished and working code of
ActionScript Code:
function ai(event:Event) :void {
if(paddlepart1.y < ball.y){
paddlepart1.y += 4.5;
paddlepart2.y += 4.5;
}else if(paddlepart2.y > ball.y){
paddlepart1.y -= 4.5;
paddlepart2.y-= 4.5;
}
}
huge thanks, its funny how simple something seems once the solution is in front of you =3