extends AnimationTree

const BLEND_ACCELERATION := 10.0
const VELOCITY_BLEND_FACTOR := 0.0643
const VELOCITY_TIMESCALE_FACTOR := 0.25

var blend: float:
	set(value):
		self["parameters/blend/blend_amount"] = value
	get:
		return self["parameters/blend/blend_amount"]

var timescale: float:
	set(value):
		self["parameters/timescale/scale"] = value
	get:
		return self["parameters/timescale/scale"]

@onready var player: Player = owner


func _process(delta: float) -> void:
	var speed := player.velocity.length()
	if player.is_on_floor():
		var timescale_target := speed * VELOCITY_TIMESCALE_FACTOR
		timescale = lerpf(timescale, timescale_target, BLEND_ACCELERATION * delta)
	else:
		timescale = 0.0

	if Game.settings.enable_head_bob:
		var blend_target := 0.0
		if player.is_on_floor():
			blend_target = speed * VELOCITY_BLEND_FACTOR

		blend = lerpf(blend, blend_target, BLEND_ACCELERATION * delta)
	else:
		blend = 0.0
