godot-plateformer/_player/ghost/ghost.gd

18 lines
647 B
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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