added movement animations

This commit is contained in:
Teatov 2025-03-03 21:01:46 +10:00
parent e9686c02b0
commit d6895b49fa
9 changed files with 10932 additions and 56 deletions

BIN
assets/models/characters/batrix.glb (Stored with Git LFS)

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
resources/animations/batrix/+idle_L.res (Stored with Git LFS)

Binary file not shown.

BIN
resources/animations/batrix/+idle_R.res (Stored with Git LFS)

Binary file not shown.

View File

@ -1,4 +1,4 @@
[gd_resource type="AnimationNodeBlendTree" load_steps=8 format=3 uid="uid://dhclwpxlgqerd"] [gd_resource type="AnimationNodeBlendTree" load_steps=19 format=3 uid="uid://dhclwpxlgqerd"]
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_tes4q"] [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_tes4q"]
animation = &"+idle_L" animation = &"+idle_L"
@ -6,35 +6,89 @@ animation = &"+idle_L"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_rdhgj"] [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_rdhgj"]
animation = &"+idle_R" animation = &"+idle_R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_sqxqa"]
animation = &"+run_forward_R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_652ho"]
animation = &"+run_back_R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_v84k8"]
animation = &"+run_left_R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_dca4u"]
animation = &"+run_right_R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_ek0q2"]
animation = &"+run_back_left_R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_8tgbo"]
animation = &"+run_back_right_R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_w4pxw"]
animation = &"+run_forward_left_R"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_t17gf"]
animation = &"+run_forward_right_R"
[sub_resource type="AnimationNodeBlendSpace2D" id="AnimationNodeBlendSpace2D_35lhb"]
blend_point_0/node = SubResource("AnimationNodeAnimation_sqxqa")
blend_point_0/pos = Vector2(0, 1)
blend_point_1/node = SubResource("AnimationNodeAnimation_652ho")
blend_point_1/pos = Vector2(0, -1)
blend_point_2/node = SubResource("AnimationNodeAnimation_v84k8")
blend_point_2/pos = Vector2(-1, 0)
blend_point_3/node = SubResource("AnimationNodeAnimation_dca4u")
blend_point_3/pos = Vector2(1, 0)
blend_point_4/node = SubResource("AnimationNodeAnimation_ek0q2")
blend_point_4/pos = Vector2(-0.71, -0.71)
blend_point_5/node = SubResource("AnimationNodeAnimation_8tgbo")
blend_point_5/pos = Vector2(0.71, -0.71)
blend_point_6/node = SubResource("AnimationNodeAnimation_w4pxw")
blend_point_6/pos = Vector2(-0.71, 0.71)
blend_point_7/node = SubResource("AnimationNodeAnimation_t17gf")
blend_point_7/pos = Vector2(0.71, 0.71)
blend_mode = 1
sync = true
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_tdamk"] [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_tdamk"]
advance_mode = 2 advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_gk5g1"]
reset = false
switch_mode = 1
advance_mode = 2
advance_condition = &"side_L"
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_v3m8c"] [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_v3m8c"]
reset = false reset = false
switch_mode = 1 switch_mode = 1
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_gk5g1"]
reset = false
switch_mode = 1
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_uj2kp"]
reset = false
switch_mode = 1
advance_mode = 2 advance_mode = 2
advance_condition = &"side_R" advance_expression = "_speed > 0.1 and _has_input"
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_3nkv7"]
reset = false
switch_mode = 1
advance_mode = 2
advance_expression = "_speed < 0.1 and not _has_input"
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_yk01a"] [sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_yk01a"]
states/+idle_L/node = SubResource("AnimationNodeAnimation_tes4q") states/+idle_L/node = SubResource("AnimationNodeAnimation_tes4q")
states/+idle_L/position = Vector2(351, 62) states/+idle_L/position = Vector2(351, 62)
states/+idle_R/node = SubResource("AnimationNodeAnimation_rdhgj") states/+idle_R/node = SubResource("AnimationNodeAnimation_rdhgj")
states/+idle_R/position = Vector2(351, 169) states/+idle_R/position = Vector2(351, 169)
transitions = ["Start", "+idle_L", SubResource("AnimationNodeStateMachineTransition_tdamk"), "+idle_R", "+idle_L", SubResource("AnimationNodeStateMachineTransition_gk5g1"), "+idle_L", "+idle_R", SubResource("AnimationNodeStateMachineTransition_v3m8c")] states/run_R/node = SubResource("AnimationNodeBlendSpace2D_35lhb")
states/run_R/position = Vector2(534, 169)
transitions = ["Start", "+idle_L", SubResource("AnimationNodeStateMachineTransition_tdamk"), "+idle_L", "+idle_R", SubResource("AnimationNodeStateMachineTransition_v3m8c"), "+idle_R", "+idle_L", SubResource("AnimationNodeStateMachineTransition_gk5g1"), "+idle_R", "run_R", SubResource("AnimationNodeStateMachineTransition_uj2kp"), "run_R", "+idle_R", SubResource("AnimationNodeStateMachineTransition_3nkv7")]
[sub_resource type="AnimationNodeTimeScale" id="AnimationNodeTimeScale_5rfjp"] [sub_resource type="AnimationNodeTimeScale" id="AnimationNodeTimeScale_5rfjp"]
[resource] [resource]
graph_offset = Vector2(2.96805, 43.4439) graph_offset = Vector2(-45.8039, 42.6208)
nodes/idle_machine/node = SubResource("AnimationNodeStateMachine_yk01a") nodes/locomotion/node = SubResource("AnimationNodeStateMachine_yk01a")
nodes/idle_machine/position = Vector2(240, 120) nodes/locomotion/position = Vector2(240, 120)
nodes/main_time_scale/node = SubResource("AnimationNodeTimeScale_5rfjp") nodes/main_time_scale/node = SubResource("AnimationNodeTimeScale_5rfjp")
nodes/main_time_scale/position = Vector2(540, 80) nodes/main_time_scale/position = Vector2(480, 100)
nodes/output/position = Vector2(780, 100) nodes/output/position = Vector2(740, 100)
node_connections = [&"main_time_scale", 0, &"idle_machine", &"output", 0, &"main_time_scale"] node_connections = [&"main_time_scale", 0, &"locomotion", &"output", 0, &"main_time_scale"]

View File

@ -110,6 +110,7 @@ bones/46/rotation = Quaternion(-0.0181733, 2.38379e-07, 1.14098e-08, 0.999835)
bones/47/rotation = Quaternion(-1.20807e-07, 0.993087, -0.117383, 7.85287e-07) bones/47/rotation = Quaternion(-1.20807e-07, 0.993087, -0.117383, 7.85287e-07)
bones/49/rotation = Quaternion(-0.034235, -3.57418e-07, 8.86969e-08, 0.999414) bones/49/rotation = Quaternion(-0.034235, -3.57418e-07, 8.86969e-08, 0.999414)
bones/51/rotation = Quaternion(0.403888, -2.98082e-07, -3.85178e-07, 0.914808) bones/51/rotation = Quaternion(0.403888, -2.98082e-07, -3.85178e-07, 0.914808)
bones/51/scale = Vector3(1, 1, 1)
bones/52/rotation = Quaternion(-0.512846, 3.82068e-07, 4.27952e-07, 0.858481) bones/52/rotation = Quaternion(-0.512846, 3.82068e-07, 4.27952e-07, 0.858481)
bones/52/scale = Vector3(1, 1, 1) bones/52/scale = Vector3(1, 1, 1)
bones/53/rotation = Quaternion(0.0772044, -1.03801e-06, -1.2885e-07, 0.997015) bones/53/rotation = Quaternion(0.0772044, -1.03801e-06, -1.2885e-07, 0.997015)
@ -244,10 +245,12 @@ root_node = NodePath("../Model")
callback_mode_process = 2 callback_mode_process = 2
tree_root = ExtResource("5_mq40n") tree_root = ExtResource("5_mq40n")
anim_player = NodePath("../Model/AnimationPlayer") anim_player = NodePath("../Model/AnimationPlayer")
parameters/idle_machine/conditions/side_L = false parameters/locomotion/run_R/blend_position = Vector2(-0.018315, -0.553192)
parameters/idle_machine/conditions/side_R = false
parameters/main_time_scale/scale = 1.0 parameters/main_time_scale/scale = 1.0
script = ExtResource("4_adlgp") script = ExtResource("4_adlgp")
_suffix_left = null
_suffix_right = null
_idle_name = null
[node name="BoneFlattener" type="Node3D" parent="." node_paths=PackedStringArray("skeleton")] [node name="BoneFlattener" type="Node3D" parent="." node_paths=PackedStringArray("skeleton")]
script = ExtResource("6_iug5b") script = ExtResource("6_iug5b")

View File

@ -32,7 +32,13 @@ func handle_input(event: InputEvent, mode: Inputer.Mode) -> void:
func controller_aiming(move_input: Vector2) -> void: func controller_aiming(move_input: Vector2) -> void:
if Referencer.players_count == 1: if Referencer.players_count == 1:
aim_input = Input.get_vector("aim_left", "aim_right", "aim_up", "aim_down") aim_input = Input.get_vector(
"aim_left",
"aim_right",
"aim_up",
"aim_down",
Settings.aiming_stick_deadzone
)
else: else:
aim_input = Inputer.get_vector_from_raw_strengths( aim_input = Inputer.get_vector_from_raw_strengths(
_aim_left, _aim_right, _aim_up, _aim_down, Settings.aiming_stick_deadzone _aim_left, _aim_right, _aim_up, _aim_down, Settings.aiming_stick_deadzone

View File

@ -1,33 +1,52 @@
extends AnimationTree extends AnimationTree
const SUFFIX_LEFT := "_L" @export_group("Animation names")
const SUFFIX_RIGHT := "_R" @export var _suffix_left := "_L"
@export var _suffix_right := "_R"
@onready var player: Player = $"../" as Player @export var _idle_name := "+idle"
@onready var attack: PlayerAttack = $"../Attack" as PlayerAttack
@onready var animation_player: AnimationPlayer = $"../Model/AnimationPlayer" var _speed: float
var _has_input: bool
@onready var _player: Player = $"../" as Player
@onready var _attack: PlayerAttack = $"../Attack" as PlayerAttack
@onready var _locomotion_playback: AnimationNodeStateMachinePlayback = get(
"parameters/locomotion/playback"
)
func _ready() -> void: func _ready() -> void:
assert(player, "player missing!") assert(_player, "_player missing!")
Music.track_started.connect(_on_music_track_started) Music.track_started.connect(_on_music_track_started)
attack.attacked.connect(_on_player_attacked) _attack.attacked.connect(_on_player_attacked)
_set_bpm() _set_bpm()
_set_side() _set_side()
func _process(_delta: float) -> void: func _process(_delta: float) -> void:
advance(Music.audio_delta as float) advance(Music.audio_delta as float)
_speed = _player.velocity.length() / _player.movement.move_speed
_has_input = _player.movement.move_input.length() > 0
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
)
Debugger.text("velocity_blend", velocity_blend, 2)
set(&"parameters/locomotion/run_R/blend_position", velocity_blend)
func _is_left() -> bool: func _is_left() -> bool:
return attack.side == PlayerAttack.Side.LEFT return _attack.side == PlayerAttack.Side.LEFT
func _suffix(invert: bool) -> String: func _suffix(invert: bool = false) -> String:
if not invert: if not invert:
return SUFFIX_LEFT if _is_left() else SUFFIX_RIGHT return _suffix_left if _is_left() else _suffix_right
return SUFFIX_LEFT if not _is_left() else SUFFIX_RIGHT return _suffix_left if not _is_left() else _suffix_right
func _set_bpm() -> void: func _set_bpm() -> void:
@ -35,8 +54,7 @@ func _set_bpm() -> void:
func _set_side() -> void: func _set_side() -> void:
set(&"parameters/idle_machine/conditions/side_L", _is_left()) _locomotion_playback.travel(_idle_name + _suffix())
set(&"parameters/idle_machine/conditions/side_R", not _is_left())
func _on_music_track_started() -> void: func _on_music_track_started() -> void:

View File

@ -1,11 +1,12 @@
class_name PlayerMovement class_name PlayerMovement
@export var _move_speed: float = 8 @export var move_speed: float = 8
@export var _move_acceleration: float = 100
@export var _move_deceleration: float = 50
@export var _fall_speed: float = 20 @export var move_acceleration: float = 100
@export var _fall_acceleration: float = 25 @export var move_deceleration: float = 50
@export var fall_speed: float = 20
@export var fall_acceleration: float = 25
var move_input: Vector2 var move_input: Vector2
@ -63,7 +64,13 @@ func movement(
func _lateral_movement(velocity: Vector3, delta: float, can_move: bool) -> Vector3: func _lateral_movement(velocity: Vector3, delta: float, can_move: bool) -> Vector3:
if Referencer.players_count == 1: if Referencer.players_count == 1:
move_input = Input.get_vector("move_left", "move_right", "move_up", "move_down") move_input = Input.get_vector(
"move_left",
"move_right",
"move_up",
"move_down",
Settings.movement_stick_deadzone
)
else: else:
move_input = Inputer.get_vector_from_raw_strengths( move_input = Inputer.get_vector_from_raw_strengths(
_move_left, _move_left,
@ -78,13 +85,13 @@ func _lateral_movement(velocity: Vector3, delta: float, can_move: bool) -> Vecto
_move_direction = Vector3(move_input.x, 0, move_input.y).normalized().rotated( _move_direction = Vector3(move_input.x, 0, move_input.y).normalized().rotated(
Vector3.UP, Referencer.main_camera.rotation.y Vector3.UP, Referencer.main_camera.rotation.y
) )
var new_velocity := _move_direction * _move_speed var new_velocity := _move_direction * move_speed
new_velocity.y = velocity.y new_velocity.y = velocity.y
velocity = velocity.move_toward(new_velocity, _move_acceleration * delta) velocity = velocity.move_toward(new_velocity, move_acceleration * delta)
else: else:
var new_velocity := Vector3.ZERO var new_velocity := Vector3.ZERO
new_velocity.y = velocity.y new_velocity.y = velocity.y
velocity = velocity.move_toward(new_velocity, _move_deceleration * delta) velocity = velocity.move_toward(new_velocity, move_deceleration * delta)
return velocity return velocity
@ -92,8 +99,8 @@ func _lateral_movement(velocity: Vector3, delta: float, can_move: bool) -> Vecto
func _vertical_movement(velocity: Vector3, delta: float, is_on_floor: bool) -> Vector3: func _vertical_movement(velocity: Vector3, delta: float, is_on_floor: bool) -> Vector3:
if not is_on_floor: if not is_on_floor:
var new_velocity := velocity var new_velocity := velocity
new_velocity.y = -_fall_speed new_velocity.y = -fall_speed
velocity = velocity.move_toward(new_velocity, _fall_acceleration * delta) velocity = velocity.move_toward(new_velocity, fall_acceleration * delta)
else: else:
velocity.y = 0 velocity.y = 0