
-----------------------------------
Velocity
Wed Dec 21, 2011 7:28 pm

Make the A.I Paddle follow the ball
-----------------------------------
What is it you are trying to achieve?
I aim to make the A.I Paddle follow the ball so that it never goes below it.

What is the problem you are having?
I am unable to make the paddle move first of all but i think this is just the same step as making it follow the ball so i want to make it follow the ball.


Describe what you have tried to solve this problem
making if statements for if the paddle is greater than this location paddle -= 10 and if it is less than this location it goes += 10, it doesnt move, it stays still

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


if ball_y2 >= maxy - 50 then
            ball_directiony2 *= -1
        end if
        if ball_x2 >= maxx div 2 + 40 then
            ball_directionx2 *= -1
        end if
        if ball_x2  x1_1 then
            x2_2 += 10
            x1_1 += 10
        elsif ball_y2 < x1_1 then
            x2_2 -= 10
            x1_1 -= 10
        end if 

insectoid i used your code but for some reason with these boundaries of my paddle 

if x2_2 > maxx - 31 and x1_1 < maxx - 131 then
            x1_1 -= 10
            x2_2 -= 10
        elsif x2_2 < maxx div 2 + 131 and x1_1 > maxx div 2
+ 31 then
            x1_1 += 10
            x2_2 += 10
        end if

the paddle goes to the left and then even when the ball moves right the paddle trys to move right but stays on the left.

-----------------------------------
Dreadnought
Thu Dec 22, 2011 7:06 pm

Re: Make the A.I Paddle follow the ball
-----------------------------------
Is it intended that you're comparing the y-coordinate of the ball with the x coordinate of the paddle?

-----------------------------------
Insectoid
Thu Dec 22, 2011 8:11 pm

RE:Make the A.I Paddle follow the ball
-----------------------------------
The paddle doesn't even need an X variable, since it only goes up and down.

-----------------------------------
Velocity
Thu Dec 22, 2011 10:35 pm

RE:Make the A.I Paddle follow the ball
-----------------------------------
mine goes left and right

-----------------------------------
Velocity
Thu Dec 22, 2011 10:35 pm

RE:Make the A.I Paddle follow the ball
-----------------------------------
its not pong, its brick breaker. Please help me to know where i went wrong :)

-----------------------------------
RandomLetters
Thu Dec 22, 2011 11:04 pm

RE:Make the A.I Paddle follow the ball
-----------------------------------
Then why are you comparing the y values of the paddle?

-----------------------------------
Velocity
Fri Dec 23, 2011 1:11 am

RE:Make the A.I Paddle follow the ball
-----------------------------------
X1-1 is the first x co'ord of the paddle
X2-2 is the second x co'ord of the paddle
Ball-y2 is the y co'ord of the a.i ball

Nowhere in the code does it say the y co'ord of the paddle

X1-1 is where the drawfill box starts
X2-2 is where it ends

How do i get my paddle to follow the ball properly, the code i prompted it with worked but when my code starts the a.i paddle goes to the left and trys to go right but a force blocks it and it doesnt. Would you feel more comfortable with my question if i provided the code for my actual game?

-----------------------------------
Velocity
Fri Dec 23, 2011 1:14 am

RE:Make the A.I Paddle follow the ball
-----------------------------------
oh wait i think i see the problem, ill try to fix it tomorrow when i get on the comp, dreadnought thanks your post shined a light in my eyess :).

-----------------------------------
Zren
Fri Dec 23, 2011 1:26 am

RE:Make the A.I Paddle follow the ball
-----------------------------------
Need Code: Yes.

What he means is why are you comparing the paddle.pos.x to ball.pos.y? The relation is on the x-axis, so you'd be comparing both x values. This is a one dimensional problem.
