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
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.
Offline
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
Offline
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
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
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
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