extends CharacterBody3D

var moveUtils = MoveUtils.new()

var fall_acceleration = 75

var target_velocity = Vector3.ZERO

func _physics_process(delta: float) -> void:
	
	target_velocity = moveUtils.get_horizontal_velocity(get_cmd_direction(), velocity, delta)
	
	if target_velocity != Vector3.ZERO:
		$pivot.basis = Basis.looking_at(target_velocity.normalized())

	if !is_on_floor():
		target_velocity.y = target_velocity.y - ( fall_acceleration * delta )
	
	velocity = target_velocity
	move_and_slide()
	
## 获取当前指令的关联向量[br]
## 难道需要两层才生效？
func get_cmd_direction() -> Vector3:
	var vector := Vector3.ZERO
	if Input.is_action_pressed("move_forward"):
		vector.z -= 1
	if Input.is_action_pressed("move_back"):
		vector.z += 1
	if Input.is_action_pressed("move_left"):
		vector.x -= 1
	if Input.is_action_pressed("move_right"):
		vector.x += 1
	return vector.normalized()
