【发布时间】:2020-02-21 20:51:25
【问题描述】:
我是 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