记录网址:监听玩家的输入 — Godot Engine (4.x) 简体中文文档
发现在完整代码存在遗漏,导致实际效果无法跟教程效果一致
添加原教程代码 rotation += angular_speed * delta
不过不是教程问题,教程本意是让我初学者理解代码,我开始看不懂,后面才明白一点点,
可惜记忆差,待会就忘了,在这里提醒未来的我,重学教程怎么做不到跟教程一样的效果
extends Sprite2D #Sprite2D, Godot将在每一帧调用该函数,并传递给它一个名为delta 的参数,及从上一帧开始经过的时间
#func _init() -> void:
#print("Hello World!")
#四处旋转
var speed =400
var angular_speed = PI
func _process(delta): #delta 时间值
rotation += angular_speed * delta
var direction = 0
if Input.is_action_pressed('ui_left'):
direction =-1
if Input.is_action_pressed('ui_right'):
direction=1
rotation += angular_speed * direction * delta
var velocity = Vector2.ZERO
if Input.is_action_pressed('ui_up'):
velocity = Vector2.UP.rotated(rotation) * speed
position += velocity * delta
323

被折叠的 条评论
为什么被折叠?



