added movement animations

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

View File

@@ -32,7 +32,13 @@ func handle_input(event: InputEvent, mode: Inputer.Mode) -> void:
func controller_aiming(move_input: Vector2) -> void:
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:
aim_input = Inputer.get_vector_from_raw_strengths(
_aim_left, _aim_right, _aim_up, _aim_down, Settings.aiming_stick_deadzone

View File

@@ -1,33 +1,52 @@
extends AnimationTree
const SUFFIX_LEFT := "_L"
const SUFFIX_RIGHT := "_R"
@export_group("Animation names")
@export var _suffix_left := "_L"
@export var _suffix_right := "_R"
@onready var player: Player = $"../" as Player
@onready var attack: PlayerAttack = $"../Attack" as PlayerAttack
@onready var animation_player: AnimationPlayer = $"../Model/AnimationPlayer"
@export var _idle_name := "+idle"
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:
assert(player, "player missing!")
assert(_player, "_player missing!")
Music.track_started.connect(_on_music_track_started)
attack.attacked.connect(_on_player_attacked)
_attack.attacked.connect(_on_player_attacked)
_set_bpm()
_set_side()
func _process(_delta: float) -> void:
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:
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:
return SUFFIX_LEFT if _is_left() else SUFFIX_RIGHT
return SUFFIX_LEFT if not _is_left() else SUFFIX_RIGHT
return _suffix_left if _is_left() else _suffix_right
return _suffix_left if not _is_left() else _suffix_right
func _set_bpm() -> void:
@@ -35,8 +54,7 @@ func _set_bpm() -> void:
func _set_side() -> void:
set(&"parameters/idle_machine/conditions/side_L", _is_left())
set(&"parameters/idle_machine/conditions/side_R", not _is_left())
_locomotion_playback.travel(_idle_name + _suffix())
func _on_music_track_started() -> void:

View File

@@ -1,11 +1,12 @@
class_name PlayerMovement
@export var _move_speed: float = 8
@export var _move_acceleration: float = 100
@export var _move_deceleration: float = 50
@export var move_speed: float = 8
@export var _fall_speed: float = 20
@export var _fall_acceleration: float = 25
@export var move_acceleration: float = 100
@export var move_deceleration: float = 50
@export var fall_speed: float = 20
@export var fall_acceleration: float = 25
var move_input: Vector2
@@ -63,7 +64,13 @@ func movement(
func _lateral_movement(velocity: Vector3, delta: float, can_move: bool) -> Vector3:
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:
move_input = Inputer.get_vector_from_raw_strengths(
_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(
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
velocity = velocity.move_toward(new_velocity, _move_acceleration * delta)
velocity = velocity.move_toward(new_velocity, move_acceleration * delta)
else:
var new_velocity := Vector3.ZERO
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
@@ -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:
if not is_on_floor:
var new_velocity := velocity
new_velocity.y = -_fall_speed
velocity = velocity.move_toward(new_velocity, _fall_acceleration * delta)
new_velocity.y = -fall_speed
velocity = velocity.move_toward(new_velocity, fall_acceleration * delta)
else:
velocity.y = 0