# remaking Pong in Godot but the opponent AI cannot locate the ball's coordinate correctly

I'm following a detailed YouTube tutorial on remaking Pong in Godot 3.0 but I have ran into an issue regarding the way the AI opponent reacts to the incoming ball, what's happening is that the opponent can track the balls' location but for some strange reason the opponent always reacts to the incoming ball as if it's more below its actual location, here's a video that shows my issue , as you can see the opponent always moves way more down than it should which makes it impossible for it to hit the ball most of the time, the only time it can hit the ball correctly is when the ball is already heading down to the corner, so it just so happens to meet up with it

I have followed the tutorial closely and downloaded the source code for the Godot project and tried copy and pasting the opponent's (and even the ball's code) to my project and I double checked the variable names and the way scene tree is organized yet the issue is still present

Here's the current code for the AI opponent:

extends KinematicBody2D

var speed = 250 #tried changing this but the issue still occurs
var ball

ball = get_parent().find_node("ball")

func _physics_process(delta):
move_and_slide(Vector2(0,get_opponent_direction()) * speed) #i tried also multiplying the speed by delta but it doesn't fix it

#the issue is in this function probably...
func get_opponent_direction():
if abs(ball.position.y - position.y) > 25: #I tried increasing\decreasing this but the issue's still present
if ball.position.y > position.y: return 1
else: return -1
else: return 0



Here's the ball's code also (even though I don't think it has anything to do with it)

extends KinematicBody2D

var speed = 400 #tried increasing\decreasing the speed but the issue is still present
var velocity = Vector2.ZERO

randomize()
velocity.x = [-1,1][randi() % 2]
velocity.y = [-0.8,0.8][randi() % 2]

func _physics_process(delta):
var collision_object = move_and_collide(velocity * speed * delta)
if collision_object:
velocity = velocity.bounce(collision_object.normal)



I even checked if the project window size is correct and it is, I also double checked that me and the tutorial are both using Godot 3.2. It seems to me that the issue is that the opponent gets the coordinates for the ball but for some reason it increases the Y axis for the coordinates, this results in the opponent seeing the ball below its actual location, so yeah something with the Y coordinates...

• Are you using the same object offsets as the tutorial (i.e are their center points measured from the same places)? That's something that is often set via the Inspector tab (on the right side of the editor UI by default) and doesn't necessarily show up in the code. Feb 26 at 15:07
• hi thanks, yeah that was the solution ! i had the opponent's collision and sprite be placed very far from the (0,0) origin point, i just dragged them over with the mouse Feb 26 at 17:58

In the Godot editor, I made the silly mistake of placing the Sprite and CollsionShape nodes far away from the (0,0) origin point.