我的
CharacterBody2D
节点上有一个用于水平移动的脚本:
extends CharacterBody2D
@export var speed = 400
func get_input():
var input_direction = Input.get_axis("ui_left", "ui_right")
print('Input direction %d' % input_direction)
velocity.x = input_direction * speed
velocity.y = 0
func _physics_process(delta):
get_input()
move_and_slide()
print('Current X = %d\n' % position.x)
查看日志,脚本似乎正在运行,因为
position.x
正在更新:
Input direction 1
Current X = 479
Input direction 1
Current X = 486
Input direction 1
Current X = 493
Input direction 1
Current X = 499
Input direction 1
Current X = 506
Input direction 1
Current X = 513
但是,当我运行场景时,角色并没有移动,它仍然静止在屏幕中间。我该如何解决?我查看了2d运动概述,但找不到任何线索。
我的场景只有一个
CharacterBody2D
节点,以下节点作为子节点:
CollisionShape2D
Sprite2D
AnimationPlayer
Camera2D
角色正在移动。我只是觉得这不是因为相机附在上面。我的环境中没有其他物体,所以我无法想象该运动。