This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-09-04 15:49:21

M303MTL
New Scratcher
Registered: 2010-09-03
Posts: 12

Pong AI

Sorry for posting so many topics in such a short span, but I'm having an odd problem.  I'm trying to put in enemy AI for this pong game, but no matter what I do, the paddle ends up spinning around and going crazy.  The basic idea seems to be to lock it down on one axis by setting either the y or x to a fixed value, and then make it point towards the ball and move.  However, whenever I do this, the paddle becomes crooked, spins and skips around the screen.  I've even tried downloading a project from here that is the sample pong game except with enemy AI.  I loaded up that and the sample game, then edited the sample to make them IDENTICAL, and the AI still didn't work in the sample I edited.

Offline

 

#2 2010-09-04 15:50:44

Sunrise-Moon
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Pong AI

Try this:
[set x to (x position of [ball])]


http://i1067.photobucket.com/albums/u427/HulKDzN/RebornBlade.png

Offline

 

#3 2010-09-04 15:59:22

M303MTL
New Scratcher
Registered: 2010-09-03
Posts: 12

Re: Pong AI

It just slowly follows the ball.

Offline

 

#4 2010-09-04 16:21:23

Telemachus
Scratcher
Registered: 2010-04-21
Posts: 500+

Re: Pong AI

Try giving the AI velocity, then basing direction on which side the ball is on in relation to the paddle. This creates a fun, beatable Ai.


http://i54.tinypic.com/10h0fnp.jpg

Offline

 

#5 2010-09-04 17:04:56

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Pong AI

Telemachus wrote:

Try giving the AI velocity, then basing direction on which side the ball is on in relation to the paddle. This creates a fun, beatable Ai.

That can be a little difficult to understand, so I made a project demonstrating that:

http://scratch.mit.edu/projects/coolfixit/1280997

Be sure to read the project notes  big_smile

Offline

 

#6 2010-09-05 13:01:12

M303MTL
New Scratcher
Registered: 2010-09-03
Posts: 12

Re: Pong AI

Sorry for the delayed response, and thank you so much for making that demonstration.  The only thing that I'm not understanding is that when I have it as the paddle being human controlled, the command "if on edge, bounce" keeps you from moving the paddle past the edge.  However, using that command on the AI doesn't stop it from moving down until only the very top of the paddle can be seen and that makes it overshoot edge shots.

Offline

 

#7 2010-09-05 13:06:07

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Pong AI

M303MTL wrote:

Sorry for the delayed response, and thank you so much for making that demonstration.  The only thing that I'm not understanding is that when I have it as the paddle being human controlled, the command "if on edge, bounce" keeps you from moving the paddle past the edge.  However, using that command on the AI doesn't stop it from moving down until only the very top of the paddle can be seen and that makes it overshoot edge shots.

I updated the project so that it should never go past the edge. It doesn't look perfect, but it works in a very satisfactory way.

Offline

 

#8 2010-09-05 13:29:37

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: Pong AI

I'm not sure what you would want a pong paddle to point towards anything? Usually they just move back and forth.


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

#9 2010-09-05 14:01:39

M303MTL
New Scratcher
Registered: 2010-09-03
Posts: 12

Re: Pong AI

Maybe it's just because I'm using a smaller paddle or its because its playing sideways (i.e. the paddles are longer vertically and the ball bounces back left and right) but in my game the AI paddle ends up getting stuck when it bounces on the edge.  It will block the low shots then miss the next two because it gets stuck and has to slowly glitch out of the edge.

Offline

 

#10 2010-09-05 14:34:19

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Pong AI

M303MTL wrote:

Maybe it's just because I'm using a smaller paddle or its because its playing sideways (i.e. the paddles are longer vertically and the ball bounces back left and right) but in my game the AI paddle ends up getting stuck when it bounces on the edge.  It will block the low shots then miss the next two because it gets stuck and has to slowly glitch out of the edge.

Hm - that's odd, it works perfectly for me. Let me make one more change and see if that fixes things up.

Offline

 

#11 2010-09-05 14:39:52

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Pong AI

OK - I think I may have fixed it now. Try it again.

Offline

 

Board footer