Weapon draw and holster

This commit is contained in:
Alexey 2025-07-27 12:32:18 +03:00
commit b4a6dadc43
18 changed files with 428 additions and 9 deletions

View file

@ -6,6 +6,7 @@ extends CharacterBody3D
@export var horizontal_sensivity = 0.005
var queue: CommandQueue = CommandQueue.new()
var queue_data: Dictionary = {}
@onready var camera: Camera3D = $"Camera"
@onready var weapon_player: AnimationPlayer = $"HUD/Weapon/AnimationPlayer"
@ -49,13 +50,12 @@ func _process(_delta: float) -> void:
# Slot changing logic
var slot_action = false
var slot_id = 0
for slot in slot_actions.size():
if Input.is_action_just_pressed(slot_actions[slot]):
slot_action = true
slot_id = slot
queue_data['slot_id'] = slot
if slot_action:
weapons.select_slot(slot_id)
push_copied_command(CommandQueue.Command.HOLSTER_WEAPON, weapon_sides)
# Stop firing logic
if not current_weapon.fire_mode is SingleFireMode:
@ -109,7 +109,8 @@ func on_weapon_slot_selected():
current_weapon.fire_allowed.connect(finish_task)
weapon_player.add_animation_library("current", current_weapon.animation_library)
weapon_player.play("current/static")
push_copied_command(CommandQueue.Command.DRAW_WEAPON, current_weapon.uses_hands)
update_ammo_label()
@ -192,6 +193,10 @@ func handle_ended_right_command(command: CommandQueue.Command):
weapon_player.play('current/static')
current_weapon.reload()
update_ammo_label()
CommandQueue.Command.HOLSTER_WEAPON:
weapons.select_slot(queue_data['slot_id'])
CommandQueue.Command.DRAW_WEAPON:
weapon_player.play('current/static')
func handle_started_left_command(command: CommandQueue.Command):
match command:
@ -203,6 +208,10 @@ func handle_started_right_command(command: CommandQueue.Command):
current_weapon.request_fire()
CommandQueue.Command.STOP_FIRING:
queue.pop()
CommandQueue.Command.DRAW_WEAPON:
weapon_player.play('current/draw')
CommandQueue.Command.HOLSTER_WEAPON:
weapon_player.play('current/holster')
func handle_current_left_command(command: CommandQueue.Command):
match command: