class_name Ghost extends CharacterBody2D var _last_frame_direction : Vector2 = Vector2(1.0,0) func _physics_process(delta: float) -> void: #优先让移动的方向等于上一帧的方向,防止出现Zero的情况,上一帧移动方向的默认值是水平向右的 var h = Input.get_axis(&"move_left",&"move_right") var v = Input.get_axis(&"move_down",&"move_up") var _current_frame_direction = Vector2(h,v).normalized() #只有在输入存在的情况下,我们才更新上一帧的方向 if _current_frame_direction != Vector2.ZERO: _last_frame_direction = _current_frame_direction var move_dir = _last_frame_direction