I'm writing a pong clone, that has an AI:
move_and_slide(Vector2(0, ball_vs_ai_position()) * speed)
where ball_vs_ai_position is:
func ball_vs_ai_position():
if abs(ball.position.y - position.y) > 25:
if ball.position.y > position.y:
return 1
else:
return -1
else:
return 0
This should make the bat move if it's more than 25 pixels away from the y position of the ball.
If the ball is under the y position of the ball move up, and vice versa.
But, it does this.
The AI is on the right bat.
Can someone explain what I'm doing wrong?
Thanks in advance 🙂