added weapon holstering
This commit is contained in:
@@ -56,7 +56,12 @@ var start_sensitivity
|
||||
@export var BASE_FOV : float = 80
|
||||
@export var FOV_CHANGE = 1.5
|
||||
|
||||
## GUNS AND AMMO
|
||||
var gun : Node
|
||||
var holstered_gun_id : int
|
||||
var gun_is_holstered = false
|
||||
|
||||
|
||||
@onready var dead_player : Resource = load("res://assets/dead_cam.tscn")
|
||||
@onready var pause_menu: Control = $Head/Recoil/Camera3D/PauseMenu
|
||||
@onready var gun_ray = $Head/Recoil/Camera3D/GunRay
|
||||
@@ -371,22 +376,30 @@ func _physics_process(delta):
|
||||
gun_folded = false
|
||||
|
||||
#Weapon Swap Up
|
||||
if Input.is_action_just_pressed("scroll_up") and !gun.anim_player.is_playing():
|
||||
if held_item == null:
|
||||
if level_control.held_guns.size() > 1:
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(level_control.current_gun_index + 1)
|
||||
if Input.is_action_just_pressed("scroll_up"):
|
||||
if gun != null:
|
||||
if !gun.anim_player.is_playing():
|
||||
if held_item == null:
|
||||
if level_control.held_guns.size() > 1:
|
||||
weapon_select(level_control.current_gun_index + 1)
|
||||
else:
|
||||
moveable_holder.rotation.y += deg_to_rad(45)
|
||||
else:
|
||||
moveable_holder.rotation.y += deg_to_rad(45)
|
||||
if gun_is_holstered:
|
||||
holster_gun(false)
|
||||
|
||||
#Weapon Swap Down
|
||||
if Input.is_action_just_pressed("scroll_down") and !gun.anim_player.is_playing():
|
||||
if held_item == null:
|
||||
if level_control.held_guns.size() > 1:
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(level_control.current_gun_index - 1)
|
||||
if Input.is_action_just_pressed("scroll_down"):
|
||||
if gun != null:
|
||||
if !gun.anim_player.is_playing():
|
||||
if held_item == null:
|
||||
if level_control.held_guns.size() > 1:
|
||||
weapon_select(level_control.current_gun_index - 1)
|
||||
else:
|
||||
moveable_holder.rotation.y -= deg_to_rad(45)
|
||||
else:
|
||||
moveable_holder.rotation.y -= deg_to_rad(45)
|
||||
if gun_is_holstered:
|
||||
holster_gun(false)
|
||||
|
||||
for i in range(1,9):
|
||||
if Input.is_action_just_pressed("numb_" + str(i)):
|
||||
@@ -394,6 +407,12 @@ func _physics_process(delta):
|
||||
if !gun.anim_player.is_playing():
|
||||
if i-1 != level_control.current_gun_index and i <= level_control.held_guns.size():
|
||||
weapon_select((i - 1))
|
||||
|
||||
if Input.is_action_just_pressed("holster"):
|
||||
if gun_is_holstered:
|
||||
holster_gun(false)
|
||||
else:
|
||||
holster_gun(true)
|
||||
|
||||
if Input.is_action_just_pressed("weapon_select"):
|
||||
weapon_select_menu.open()
|
||||
@@ -476,6 +495,17 @@ func joypad_look(delta):
|
||||
head.rotate_x(-yAxis * JOYSTICK_SENSITIVITY * 1)
|
||||
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-90), deg_to_rad(85))
|
||||
|
||||
func holster_gun(holster):
|
||||
if holster:
|
||||
gun_is_holstered = true
|
||||
if gun != null:
|
||||
holstered_gun_id = level_control.current_gun_index
|
||||
gun.anim_player.play("swap_out")
|
||||
else:
|
||||
gun_is_holstered = false
|
||||
if holstered_gun_id != null:
|
||||
weapon_select(holstered_gun_id)
|
||||
|
||||
func flashlight_toggle():
|
||||
if flashlight_on:
|
||||
flashlight.light_energy = FLASHLIGHT_BRIGHTNESS
|
||||
@@ -554,8 +584,9 @@ func weapon_sway(delta):
|
||||
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, (mouse_input.y + joy_input.y) * weapon_sway_amount, 5 * delta)
|
||||
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, (mouse_input.x + joy_input.x) * weapon_sway_amount, 5 * delta)
|
||||
else:
|
||||
if gun.ads == true:
|
||||
weapon_holder.rotation = Vector3.ZERO
|
||||
if gun:
|
||||
if gun.ads == true:
|
||||
weapon_holder.rotation = Vector3.ZERO
|
||||
|
||||
func weapon_bob(vel : float, delta):
|
||||
if weapon_holder:
|
||||
@@ -570,8 +601,10 @@ func weapon_bob(vel : float, delta):
|
||||
weapon_holder.position.x = lerp(weapon_holder.position.x, def_weapon_holder_pos.x, .1 * delta)
|
||||
|
||||
func weapon_select(gun_id):
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(gun_id)
|
||||
if gun != null:
|
||||
gun.anim_player.play("swap_out")
|
||||
if gun_id != null:
|
||||
level_control.gun_spawn(gun_id)
|
||||
|
||||
func enemy_hit():
|
||||
var hitmarker_spawn = hitmarker.instantiate()
|
||||
@@ -594,6 +627,7 @@ func toggle_hud(hud_on):
|
||||
hud.visible = hud_on
|
||||
|
||||
func grab_moveable(body):
|
||||
holster_gun(true)
|
||||
held_item = body
|
||||
#cache rigidbody settings
|
||||
held_item_linear_damp_cache = body.linear_damp
|
||||
@@ -626,6 +660,7 @@ func hold_item(_delta):
|
||||
release_moveable()
|
||||
|
||||
func release_moveable():
|
||||
holster_gun(false)
|
||||
if held_item != null:
|
||||
held_item.gravity_scale = held_item_gravity_cache
|
||||
held_item.linear_damp = held_item_linear_damp_cache
|
||||
|
||||
Reference in New Issue
Block a user