AI "Pong" Paddle
by Chris · in Torque Game Builder · 05/03/2009 (12:42 pm) · 1 replies
Hey guys,
Working on a Pong clone as one of my first projects and I've gotten to the point where I'm trying to allow the player to play a single player game by making one of the paddles run off an AI script.
I have it working using the following script that gets called any time the ball is served.
I know it's a bit simplistic, but the paddle is moving around, trying to get to the ball. I have two questions though.
First up, the paddles have world limits to keep them from moving all the way across the screen. When the ball is on the other side of the court, the AI paddle will move up to the world limit and just keep bouncing off the worldlimit until the ball comes back. Is there any way to stop that?
Second, the schedule is the only way I could figure out how to have the paddle constantly try to get to the ball was to keep running the function. But I've noticed, it does chew up resources and when I exit out of the game to the main menu, it keeps running. Is there a way to 'unschedule' a function that is looping it's own schedule like that? Or is there just a plain better way to handle the paddle movement that doesn't involve looping the scheduled function?
Thanks in advance!
Working on a Pong clone as one of my first projects and I've gotten to the point where I'm trying to allow the player to play a single player game by making one of the paddles run off an AI script.
I have it working using the following script that gets called any time the ball is served.
function AIMove(%this){
$redPaddle.moveTo($theball.getPositionX() SPC $theball.getPositionY(),35,true, false, false, 0.1);
schedule(500,0,"AIMove");
}I know it's a bit simplistic, but the paddle is moving around, trying to get to the ball. I have two questions though.
First up, the paddles have world limits to keep them from moving all the way across the screen. When the ball is on the other side of the court, the AI paddle will move up to the world limit and just keep bouncing off the worldlimit until the ball comes back. Is there any way to stop that?
Second, the schedule is the only way I could figure out how to have the paddle constantly try to get to the ball was to keep running the function. But I've noticed, it does chew up resources and when I exit out of the game to the main menu, it keeps running. Is there a way to 'unschedule' a function that is looping it's own schedule like that? Or is there just a plain better way to handle the paddle movement that doesn't involve looping the scheduled function?
Thanks in advance!
About the author
Torque Owner Tyler Slabinski