Computer Science Canada Make the A.I Paddle follow the ball |
Author: | Velocity [ Wed Dec 21, 2011 7:28 pm ] | ||
Post subject: | 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)
Please specify what version of Turing you are using 4.1.1a |
Author: | Velocity [ Wed Dec 21, 2011 7:50 pm ] |
Post subject: | RE:Make the A.I Paddle follow the ball |
+ karma for help, need to make it in the next 10mins |
Author: | RandomLetters [ Wed Dec 21, 2011 9:05 pm ] |
Post subject: | RE:Make the A.I Paddle follow the ball |
If you want it to follow the ball, then you will need to use the ball's coordinates somehow. A simple way is to just draw the paddle where the ball is x1 = 10 x2 = 20 y1 = by + 10 y2 = by - 10 better (beatable way) is to check the location of the paddle, compare it to the location of the ball, and move appropriately for example, y = 0 if deltay > max then //check if the paddle is above the ball and set it to move down v = -1 end if y += v y1= y + 10 y2 = y - 10 |
Author: | Zren [ Wed Dec 21, 2011 10:36 pm ] | ||
Post subject: | RE:Make the A.I Paddle follow the ball | ||
So much hardcoding... If you use a number more than once for a specific value (Eg: ball radius, ball speed, paddle speed) then you should make a variable or constant for it. Actually, you should always use a variable to describe 'magic numbers' even if you only use the variable once. It makes the code more readable. Building on what Rand was talking about: You also need to take into account when the object's destination is within the movement speed. Otherwise you'll get a jittery effect as one frame it's on the left, next on the right, etc.
|
Author: | Velocity [ Thu Dec 22, 2011 12:17 pm ] |
Post subject: | RE:Make the A.I Paddle follow the ball |
zren i implemented your code into my program and changed the co-ords around a little, and the a.i paddle moves where the ball is but it only twitches like + 5 on the co-ord that way... so it doesnt exactly follow it only + 5 out of 100, this is how i put your code in : var paddle_speed : int := 5 var shadower := ball_x2 - x2_2 if abs (shadower) <= paddle_speed then x2_2 := ball_x2 x1_1 := ball_x2 elsif shadower > 100 then x1_1 := x1_1 + paddle_speed + 100 x1_1 := x2_2 - paddle_speed - 100 elsif shadower < 100 then x2_2 := x1_1 - paddle_speed - 100 x2_2 := x1_1 + paddle_speed + 100 end if |
Author: | Velocity [ Thu Dec 22, 2011 12:21 pm ] |
Post subject: | RE:Make the A.I Paddle follow the ball |
This changed the paddle speed but ithen the paddle moves and it gets to the maxx and disappears var paddle_speed : int := 50 var shadower := ball_x2 - x2_2 if abs (shadower) <= paddle_speed then x2_2 := ball_x2 x1_1 := ball_x2 elsif shadower > 100 then x1_1 := x1_1 + paddle_speed + 200 elsif shadower < 100 then x2_2 := x1_1 - paddle_speed - 100 end if |
Author: | Insectoid [ Thu Dec 22, 2011 1:01 pm ] | ||
Post subject: | RE:Make the A.I Paddle follow the ball | ||
You're severely over-complicating this.
It's that simple. |
Author: | Velocity [ Thu Dec 22, 2011 6:12 pm ] |
Post subject: | RE:Make the A.I Paddle follow the ball |
insectoid thank you so much that helped alot! +karma |
Author: | Velocity [ Thu Dec 22, 2011 6:46 pm ] |
Post subject: | RE:Make the A.I Paddle follow the ball |
if ball_y2 > 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. |
Author: | Dreadnought [ Thu Dec 22, 2011 7:06 pm ] |
Post subject: | 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? |
Author: | Insectoid [ Thu Dec 22, 2011 8:11 pm ] |
Post subject: | 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. |
Author: | Velocity [ Thu Dec 22, 2011 10:35 pm ] |
Post subject: | RE:Make the A.I Paddle follow the ball |
mine goes left and right |
Author: | Velocity [ Thu Dec 22, 2011 10:35 pm ] |
Post subject: | RE:Make the A.I Paddle follow the ball |
its not pong, its brick breaker. Please help me to know where i went wrong ![]() |
Author: | RandomLetters [ Thu Dec 22, 2011 11:04 pm ] |
Post subject: | RE:Make the A.I Paddle follow the ball |
Then why are you comparing the y values of the paddle? |
Author: | Velocity [ Fri Dec 23, 2011 1:11 am ] |
Post subject: | 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? |
Author: | Velocity [ Fri Dec 23, 2011 1:14 am ] |
Post subject: | 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 ![]() |
Author: | Zren [ Fri Dec 23, 2011 1:26 am ] |
Post subject: | 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. |