Sort:  

Yeah, ideally, I should also make sure that the ball hit the table exactly once before any of the players hit it as well. Pls upvote me too, I'm also totally not a hindu bot.

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.16
TRX 0.16
JST 0.030
BTC 59111.01
ETH 2441.11
USDT 1.00
SBD 2.45