godot AI乒乓球动作笨拙

问题描述 投票:0回答:1

我是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)```
artificial-intelligence pong godot
1个回答
0
投票

如果不重复以下代码会发生什么?

© www.soinside.com 2019 - 2024. All rights reserved.