72 lines
1.7 KiB
GDScript
72 lines
1.7 KiB
GDScript
extends AnimationTree
|
|
|
|
var _speed: float
|
|
var _has_input: bool
|
|
|
|
@onready var _player: Player = $"../" as Player
|
|
@onready var _attack: PlayerAttack = $"../Attack" as PlayerAttack
|
|
@onready var _bone_flipper: BoneFlipper = $"../Model/Armature/Skeleton3D/BoneFlipper"
|
|
|
|
|
|
func _ready() -> void:
|
|
assert(_player, "_player missing!")
|
|
Music.track_started.connect(_on_music_track_started)
|
|
_set_bpm()
|
|
_attack.attacked.connect(_on_attack_attacked)
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
_bone_flipper.flip = _is_left()
|
|
var has_input_prev := _has_input
|
|
|
|
_speed = _player.velocity.length() / _player.movement.move_speed
|
|
_has_input = (
|
|
_player.movement.move_input.length() > 0 and not _player.attack.is_hitting()
|
|
)
|
|
|
|
var velocity_relative := _player.to_local(
|
|
_player.global_position + _player.velocity
|
|
)
|
|
var velocity_blend := (
|
|
Vector2(-velocity_relative.x, velocity_relative.z) / _player.movement.move_speed
|
|
)
|
|
|
|
if _is_left():
|
|
velocity_blend.x = -velocity_blend.x
|
|
|
|
Debugger.text("velocity_blend", velocity_blend, 2)
|
|
set(&"parameters/locomotion/run/blend_position", velocity_blend)
|
|
|
|
if has_input_prev != _has_input:
|
|
if _has_input:
|
|
_abort_oneshots()
|
|
else:
|
|
_run_to_idle()
|
|
|
|
|
|
func _is_left() -> bool:
|
|
return _attack.side == PlayerAttack.Side.LEFT
|
|
|
|
|
|
func _set_bpm() -> void:
|
|
set(&"parameters/main_time_scale/scale", Music.bpm_factor)
|
|
|
|
|
|
func _run_to_idle() -> void:
|
|
set(
|
|
&"parameters/run->idle_oneshot/request",
|
|
AnimationNodeOneShot.ONE_SHOT_REQUEST_FIRE
|
|
)
|
|
|
|
|
|
func _abort_oneshots() -> void:
|
|
set(&"parameters/hit_oneshot/request", AnimationNodeOneShot.ONE_SHOT_REQUEST_ABORT)
|
|
|
|
|
|
func _on_attack_attacked() -> void:
|
|
set(&"parameters/hit_oneshot/request", AnimationNodeOneShot.ONE_SHOT_REQUEST_FIRE)
|
|
|
|
|
|
func _on_music_track_started() -> void:
|
|
_set_bpm()
|