So I have the following code expressing the "AI" movement. pdl_R is the AI paddle, AIH is AI Height, AIHS is AI Height Speed. I want the code to move the paddle by AIH in the direction of AIHS.
pdl_R.y=AIH;
AIH+=(3*AIHS);
if(pdl_R.y==stage.stageHeight || pdl_R.y==stage.stageHeight-pdl_R.height)
{
AIHS*=-1;
}
But when the pdl_R (the AI paddle) reaches the bottom of the screen (down is the default direction), it stays there and flickers up and down by 3 pixels (instead of the expected direction switch).
My initial AIH is 200 and my initial AIHS is 1.
When your AIH reaches stage.stageHeight, the following happens:
A fix will be to place increment of AIH after you alter AIHS. This is actually the most common cause of errors, you first apply unchanged value, then change it, instead of first changing, then applying.