我是godot的新手,正在练习乒乓球游戏,我尝试制作AI并成功了,但是当球靠近球拍时,动作非常笨拙这是我的代码:
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)```
如果不重复以下代码会发生什么?