AI_Engine:
if iPaddle1Y + 10 > iBallY and iBallX < 400
fMoveComputerPaddleUp = true
fMoveComputerPaddleDown = false
endif
if iPaddle1Y + 60 < iBallY and iBallX < 400
fMoveComputerPaddleDown = true
fMoveComputerPaddleUp = false
endif
return
Newbie to AI, need Pong AI help!
I am trying to make some AI for my pong game.
I have this now, and it works, but some times the computer paddle is choppy.
Like it wants to go up and down.
Know how to fix this?
[Edited by - Fixxer on July 9, 2006 10:34:58 AM]
Well you could make the second if an elseif and then have an else statement that sets both your bools to false. That should fix the problem (assuming that is what is actually causing the problem).
Personally I don't see why you don't use an integer called vy. When you want to move up you would set it to -1 and when you want to move down you would set it to 1. Then all you have to do is add the vy variable to your y position.
Personally I don't see why you don't use an integer called vy. When you want to move up you would set it to -1 and when you want to move down you would set it to 1. Then all you have to do is add the vy variable to your y position.
July 09, 2006 08:05 PM
you could check the distance between the y coordinate of the ai paddle and the ball and if it is less then the amount the paddle will move then make it so the paddle won't move
I think the problem is you don't have it doing anything when your two conditions aren't met. You should have an else statment that set both move flags to false. I created an airhockey game once, what I did was have the computer move to a defensive position when the puck was on the other side of the table. That could be just center of the screen.
You may not be using a timer, newPos += acceleration * deltaTime, this prevents the choppiness you get because you don't know how long each frame takes so you have to calculate it.
You may not be using a timer, newPos += acceleration * deltaTime, this prevents the choppiness you get because you don't know how long each frame takes so you have to calculate it.
Adamhttp://www.allgamedevelopment.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement