I need help making an opponent for my game



So I am making a game like virtual Ping Pong. You've probably seen it before. The very old version looks like this:

I have the movement controls of your paddle, but I can't figure out how to make an A.I. that can calculate where the ball will go and hit it back in that location.

It would also help a lot if someone can tell me how to make the ball move at different angles (ex. the ball hits middle of paddle and it goes forward)

Thanks so much! I will credit you if you help! :wink:


Search stradyvarious on hopscotch and you'll see CRAZY AIR HOCKEY+stradyvarious i remixed. See the code when the red ball hits the black sides.Example- you set an angle like 45 degrees when the ball hits the sides so it moves froward at that angle. Have the paddle made from 3 squares that move the same way/speed. when ball hits middle square have ball angle straight. when hits the left square set angle 45 degrees left. when hits right square set angle 45 degrees right. As for A.I. have the cpu forever check the y position of ball. if lower than cpu then move ? -Y. if higher then move ? +Y. adjust the cpu speed so its not too fast.


https://c.gethopscotch.com/p/xg95uoq32 hers the link.


Thanks @Stradyvarious! I'll check it out