i'm new to godot and am making a pong game to practice, i tried making an AI and it works but the movement is extremely clunky when the ball gets near to the paddle
here's my code:
var speed: = Vector2(0.0 , 100.0)
var direction: = Vector2(0.0,0.0)
var velocity:= Vector2(0.0,0.0)
Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass
Called every frame. 'delta' is the elapsed time since the previous frame.
func physicsprocess(delta: float) -> void:
position.x = 135
var ball = getparent().getnode("ball").position
if ball.y < position.y:
direction.y = -1
velocity = speed * direction
moveandslide(velocity)
elif ball.y > position.y:
direction.y = 1
velocity = speed * direction
moveandslide(velocity)