Sort:  

How did you manage the "AI"? All i did is take the vertical velocity of the ball minus 5 xD It is hard to score but possible :D

Once the ball falls below the top of the net on the bot's side, the bot racket's yVelocity is given by wantedBallYVelocity+ballYvelocity (where ballYVelocity is a negative number). This ensures that the ball always bounces up with a yVelocity given by wantedBallYVelocity. The yVelocity will vary slightly, though, since the inertia defined for the racket limits how quickly it can accelerate.

When it comes to the racket's xVelocity, it actually just matched that of the ball, which was actually a problem after I introduced air resistance. If the player did not hit the ball enough sideways, it might actually stop moving sideways, causing the bot to just bounce it up and down. I solved this by always moving the bot's racket slightly towards the net right before the ball hit the racket. This ensures that the bot will always move the ball towards the net and eventually get it over.

Coin Marketplace

STEEM 0.17
TRX 0.16
JST 0.029
BTC 61048.59
ETH 2372.60
USDT 1.00
SBD 2.54