tweaks
This commit is contained in:
@@ -14,10 +14,10 @@ const CROUCHED_POS = Vector3(0,-.1,0)
|
|||||||
const STAND_POS = Vector3(0,0.889,0)
|
const STAND_POS = Vector3(0,0.889,0)
|
||||||
const SLOWSPEED = .1
|
const SLOWSPEED = .1
|
||||||
const MAX_STAMINA : float = 100
|
const MAX_STAMINA : float = 100
|
||||||
const STAMINA_DRAIN = 100 #multiplied times the delta when draining
|
const STAMINA_DRAIN = 20
|
||||||
const BOB_FREQ = 1.7
|
const BOB_FREQ = 1.7
|
||||||
const BOB_AMP = 0.08
|
const BOB_AMP = 0.08
|
||||||
|
const ADS_POS = Vector3(0,-.05,-.45)
|
||||||
var speed
|
var speed
|
||||||
var double_jump = true
|
var double_jump = true
|
||||||
var air_dash = MAX_AIR_DASH
|
var air_dash = MAX_AIR_DASH
|
||||||
@@ -28,6 +28,7 @@ var default_gravity = gravity
|
|||||||
var moving_fast = false
|
var moving_fast = false
|
||||||
var moving_fast_top_speed = 0.0
|
var moving_fast_top_speed = 0.0
|
||||||
var mouse_input : Vector2
|
var mouse_input : Vector2
|
||||||
|
var ads : bool
|
||||||
|
|
||||||
@export_group("Game Settings")
|
@export_group("Game Settings")
|
||||||
@export var AUDIO = true
|
@export var AUDIO = true
|
||||||
@@ -40,7 +41,7 @@ var start_sensitivity
|
|||||||
@export_subgroup("Head Bob & Gun Sway")
|
@export_subgroup("Head Bob & Gun Sway")
|
||||||
@export var t_bob = 1.0
|
@export var t_bob = 1.0
|
||||||
@export var weapon_holder : Node3D
|
@export var weapon_holder : Node3D
|
||||||
@export var weapon_sway_amount : float = .07
|
@export var weapon_sway_amount : float = .14
|
||||||
@export var weapon_rotation_amount : float = .07
|
@export var weapon_rotation_amount : float = .07
|
||||||
@export_subgroup("FOV")
|
@export_subgroup("FOV")
|
||||||
@export var BASE_FOV : float = 80
|
@export var BASE_FOV : float = 80
|
||||||
@@ -82,6 +83,10 @@ var hold_offset
|
|||||||
var held_item_rotation = Vector3(0,0,0)
|
var held_item_rotation = Vector3(0,0,0)
|
||||||
var gamespeed_controlled = false
|
var gamespeed_controlled = false
|
||||||
var crouched = false
|
var crouched = false
|
||||||
|
var flashlight_on : bool = false
|
||||||
|
|
||||||
|
##CACHED VARS
|
||||||
|
var weapon_start_pos
|
||||||
|
|
||||||
# Slow Down Variables
|
# Slow Down Variables
|
||||||
var remaining_stamina : float = MAX_STAMINA
|
var remaining_stamina : float = MAX_STAMINA
|
||||||
@@ -124,10 +129,12 @@ var controlled_elsewhere = false
|
|||||||
@onready var crouching_collision: CollisionShape3D = $CrouchingCollision
|
@onready var crouching_collision: CollisionShape3D = $CrouchingCollision
|
||||||
@onready var crouch_check: RayCast3D = $CrouchingCollision/CrouchCheck
|
@onready var crouch_check: RayCast3D = $CrouchingCollision/CrouchCheck
|
||||||
@onready var hit_head: AudioStreamPlayer3D = $Audio/HitHead
|
@onready var hit_head: AudioStreamPlayer3D = $Audio/HitHead
|
||||||
|
@onready var crouch_audio: AudioStreamPlayer3D = $Audio/Crouch
|
||||||
|
@onready var hud: Control = $Head/Recoil/Camera3D/HUD
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
level_control.player = self
|
||||||
SignalBus.enemy_hit.connect(enemy_hit)
|
SignalBus.enemy_hit.connect(enemy_hit)
|
||||||
SignalBus.enemy_killed.connect(enemy_killed)
|
SignalBus.enemy_killed.connect(enemy_killed)
|
||||||
|
|
||||||
@@ -146,6 +153,9 @@ func _ready():
|
|||||||
|
|
||||||
crt_filter.visible = false
|
crt_filter.visible = false
|
||||||
|
|
||||||
|
#Cache vars
|
||||||
|
weapon_start_pos = weapon_spawner.position
|
||||||
|
|
||||||
#turn off audio if unchecked in player
|
#turn off audio if unchecked in player
|
||||||
if AUDIO == false:
|
if AUDIO == false:
|
||||||
AudioServer.set_bus_volume_db(0,-80)
|
AudioServer.set_bus_volume_db(0,-80)
|
||||||
@@ -192,13 +202,15 @@ func _physics_process(delta):
|
|||||||
if crouched:
|
if crouched:
|
||||||
if !crouch_check.is_colliding():
|
if !crouch_check.is_colliding():
|
||||||
crouched = !crouched
|
crouched = !crouched
|
||||||
recoil.add_recoil(Vector3(-.2,.01,.01),5,10)
|
recoil.add_recoil(Vector3(-.2,.03,.03),5,10)
|
||||||
|
crouch_audio.play()
|
||||||
else:
|
else:
|
||||||
recoil.add_recoil(Vector3(-.2,.01,.01),20,10)
|
recoil.add_recoil(Vector3(-.2,.03,.03),20,10)
|
||||||
hit_head.play()
|
hit_head.play()
|
||||||
else:
|
else:
|
||||||
crouched = !crouched
|
crouched = !crouched
|
||||||
recoil.add_recoil(Vector3(.2,0,0),5,10)
|
recoil.add_recoil(Vector3(.2,0,0),5,10)
|
||||||
|
crouch_audio.play()
|
||||||
|
|
||||||
|
|
||||||
# Get the input direction and handle the movement/deceleration.
|
# Get the input direction and handle the movement/deceleration.
|
||||||
@@ -270,25 +282,27 @@ func _physics_process(delta):
|
|||||||
# Game Speed
|
# Game Speed
|
||||||
if !level_control.paused:
|
if !level_control.paused:
|
||||||
if Input.is_action_pressed("slow_down") and remaining_stamina > 0 :
|
if Input.is_action_pressed("slow_down") and remaining_stamina > 0 :
|
||||||
|
ads = true
|
||||||
if !gamespeed_controlled:
|
if !gamespeed_controlled:
|
||||||
Engine.time_scale = lerp(Engine.time_scale, SLOWSPEED, delta * 20)
|
Engine.time_scale = lerp(Engine.time_scale, SLOWSPEED, delta * 20)
|
||||||
gun.random_spread_amt = 0
|
#gun.random_spread_amt = 0
|
||||||
AudioServer.set_bus_effect_enabled(0,0,true)
|
AudioServer.set_bus_effect_enabled(0,0,true)
|
||||||
camera.fov = lerp(camera.fov, camera.fov * gun.fov_zoom_amt, delta * 100)
|
camera.fov = lerp(camera.fov, camera.fov * gun.fov_zoom_amt, delta * 100)
|
||||||
if sensitivity_shift == true:
|
if sensitivity_shift == true:
|
||||||
SENSITIVITY = lerp(SENSITIVITY, SENSITIVITY * .998, delta * 100)
|
SENSITIVITY = lerp(SENSITIVITY, SENSITIVITY * .998, delta * 100)
|
||||||
if remaining_stamina > 0:
|
if remaining_stamina > 0:
|
||||||
remaining_stamina = clamp(remaining_stamina - (delta * STAMINA_DRAIN),0,MAX_STAMINA)
|
remaining_stamina = clamp(remaining_stamina - ((delta * STAMINA_DRAIN)/Engine.time_scale),0,MAX_STAMINA)
|
||||||
else:
|
else:
|
||||||
|
ads = false
|
||||||
if !gamespeed_controlled:
|
if !gamespeed_controlled:
|
||||||
Engine.time_scale = lerp(Engine.time_scale, 1.0, delta * 50)
|
Engine.time_scale = lerp(Engine.time_scale, 1.0, delta * 50)
|
||||||
gun.random_spread_amt = gun.random_spread_start
|
#gun.random_spread_amt = gun.random_spread_start
|
||||||
AudioServer.set_bus_effect_enabled(0,0,false)
|
AudioServer.set_bus_effect_enabled(0,0,false)
|
||||||
if sensitivity_shift == true:
|
if sensitivity_shift == true:
|
||||||
camera.fov = lerp(camera.fov, BASE_FOV, delta * .5)
|
camera.fov = lerp(camera.fov, BASE_FOV, delta * .5)
|
||||||
SENSITIVITY = start_sensitivity
|
SENSITIVITY = start_sensitivity
|
||||||
if remaining_stamina < MAX_STAMINA and !Input.is_action_pressed("slow_down"):
|
if remaining_stamina < MAX_STAMINA and !Input.is_action_pressed("slow_down"):
|
||||||
remaining_stamina = clamp(remaining_stamina + (delta * STAMINA_DRAIN/10), 0, MAX_STAMINA)
|
remaining_stamina = clamp(remaining_stamina + (delta * STAMINA_DRAIN/Engine.time_scale), 0, MAX_STAMINA)
|
||||||
|
|
||||||
|
|
||||||
# Reloading
|
# Reloading
|
||||||
@@ -299,20 +313,22 @@ func _physics_process(delta):
|
|||||||
gun.anim_player.play("inspect")
|
gun.anim_player.play("inspect")
|
||||||
|
|
||||||
if Input.is_action_just_pressed("flashlight"):
|
if Input.is_action_just_pressed("flashlight"):
|
||||||
flashlight_audio.play()
|
if flashlight_on:
|
||||||
if flashlight.light_energy == 0:
|
flashlight_on = false
|
||||||
while flashlight.light_energy != FLASHLIGHT_BRIGHTNESS:
|
flashlight_audio.play()
|
||||||
flashlight.light_energy = FLASHLIGHT_BRIGHTNESS
|
else:
|
||||||
elif flashlight.light_energy > 0:
|
flashlight_on = true
|
||||||
flashlight.light_energy = 0
|
flashlight_audio.play()
|
||||||
|
|
||||||
|
|
||||||
# Shooting & fire modes
|
# Shooting & fire modes
|
||||||
if Input.is_action_pressed("shoot"):
|
if Input.is_action_pressed("shoot"):
|
||||||
gun.shoot(delta)
|
if gun:
|
||||||
|
gun.shoot(delta)
|
||||||
|
|
||||||
if Input.is_action_just_released("shoot"):
|
if Input.is_action_just_released("shoot"):
|
||||||
gun.cycle_count = gun.cycle_count_start
|
if gun:
|
||||||
|
gun.cycle_count = gun.cycle_count_start
|
||||||
|
|
||||||
# Gun folding out of the way
|
# Gun folding out of the way
|
||||||
if gun_ray.is_colliding():
|
if gun_ray.is_colliding():
|
||||||
@@ -377,6 +393,8 @@ func _physics_process(delta):
|
|||||||
if level_control.health <= 0:
|
if level_control.health <= 0:
|
||||||
level_control.die()
|
level_control.die()
|
||||||
|
|
||||||
|
aim_down_sights(delta)
|
||||||
|
flashlight_toggle()
|
||||||
hold_item(delta)
|
hold_item(delta)
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
crouch(delta)
|
crouch(delta)
|
||||||
@@ -384,6 +402,12 @@ func _physics_process(delta):
|
|||||||
weapon_sway(delta)
|
weapon_sway(delta)
|
||||||
weapon_bob(velocity.length(), delta)
|
weapon_bob(velocity.length(), delta)
|
||||||
|
|
||||||
|
func flashlight_toggle():
|
||||||
|
if flashlight_on:
|
||||||
|
flashlight.light_energy = FLASHLIGHT_BRIGHTNESS
|
||||||
|
else:
|
||||||
|
flashlight.light_energy = 0
|
||||||
|
|
||||||
func crouch(delta):
|
func crouch(delta):
|
||||||
if crouched:
|
if crouched:
|
||||||
crouching_collision.disabled = false
|
crouching_collision.disabled = false
|
||||||
@@ -398,6 +422,17 @@ func crouch(delta):
|
|||||||
head.position = lerp(head.position, STAND_POS, delta * 8)
|
head.position = lerp(head.position, STAND_POS, delta * 8)
|
||||||
speed = WALK_SPEED
|
speed = WALK_SPEED
|
||||||
|
|
||||||
|
func aim_down_sights(delta):
|
||||||
|
if gun:
|
||||||
|
if gun.ads == true:
|
||||||
|
if ads:
|
||||||
|
crosshair.visible = false
|
||||||
|
camera.fov -= .1
|
||||||
|
gun.position = lerp(gun.position,ADS_POS,delta * 10 / Engine.time_scale)
|
||||||
|
else:
|
||||||
|
crosshair.visible = true
|
||||||
|
gun.position = lerp(gun.position, weapon_start_pos,delta * 2)
|
||||||
|
|
||||||
func _headbob(time) -> Vector3:
|
func _headbob(time) -> Vector3:
|
||||||
var pos = Vector3.ZERO
|
var pos = Vector3.ZERO
|
||||||
pos.y = sin(time * BOB_FREQ) * BOB_AMP
|
pos.y = sin(time * BOB_FREQ) * BOB_AMP
|
||||||
@@ -434,9 +469,10 @@ func weapon_tilt(input_x, delta):
|
|||||||
camera.rotation.z = lerp(camera.rotation.z, -input_x * .075, 5 * delta)
|
camera.rotation.z = lerp(camera.rotation.z, -input_x * .075, 5 * delta)
|
||||||
|
|
||||||
func weapon_sway(delta):
|
func weapon_sway(delta):
|
||||||
mouse_input = lerp(mouse_input, Vector2.ZERO, 10 * delta)
|
if !ads:
|
||||||
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, mouse_input.y * weapon_sway_amount, 5 * delta)
|
mouse_input = lerp(mouse_input, Vector2.ZERO, 10 * delta)
|
||||||
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, mouse_input.x * weapon_sway_amount, 5 * delta)
|
weapon_holder.rotation.x = lerp(weapon_holder.rotation.x, mouse_input.y * weapon_sway_amount, 5 * delta)
|
||||||
|
weapon_holder.rotation.y = lerp(weapon_holder.rotation.y, mouse_input.x * weapon_sway_amount, 5 * delta)
|
||||||
|
|
||||||
func weapon_bob(vel : float, delta):
|
func weapon_bob(vel : float, delta):
|
||||||
if weapon_holder:
|
if weapon_holder:
|
||||||
@@ -451,9 +487,12 @@ func weapon_bob(vel : float, delta):
|
|||||||
weapon_holder.position.x = lerp(weapon_holder.position.x, def_weapon_holder_pos.x, .1 * delta)
|
weapon_holder.position.x = lerp(weapon_holder.position.x, def_weapon_holder_pos.x, .1 * delta)
|
||||||
|
|
||||||
func weapon_select(gun_id):
|
func weapon_select(gun_id):
|
||||||
if !gun.anim_player.is_playing():
|
if gun != null:
|
||||||
if level_control.held_guns.size() >= (gun_id + 1) and level_control.current_gun_index != gun_id:
|
if !gun.anim_player.is_playing():
|
||||||
gun.anim_player.play("swap_out")
|
if level_control.held_guns.size() >= (gun_id + 1) and level_control.current_gun_index != gun_id:
|
||||||
|
gun.anim_player.play("swap_out")
|
||||||
|
level_control.gun_spawn(gun_id)
|
||||||
|
else:
|
||||||
level_control.gun_spawn(gun_id)
|
level_control.gun_spawn(gun_id)
|
||||||
|
|
||||||
func enemy_hit():
|
func enemy_hit():
|
||||||
@@ -471,13 +510,10 @@ func enemy_killed():
|
|||||||
enemy_killed_audio.play()
|
enemy_killed_audio.play()
|
||||||
|
|
||||||
func toggle_hud(hud_on):
|
func toggle_hud(hud_on):
|
||||||
|
|
||||||
if dead:
|
if dead:
|
||||||
crt_filter.visible = false#hud_on
|
crt_filter.visible = false
|
||||||
else:
|
else:
|
||||||
crosshair.visible = hud_on
|
hud.visible = hud_on
|
||||||
ammo_counter.visible = hud_on
|
|
||||||
stamina_counter.visible = hud_on
|
|
||||||
|
|
||||||
func grab_moveable(body):
|
func grab_moveable(body):
|
||||||
held_item = body
|
held_item = body
|
||||||
@@ -542,7 +578,7 @@ func save():
|
|||||||
"rot_x" : rotation.x,
|
"rot_x" : rotation.x,
|
||||||
"rot_y" : rotation.y,
|
"rot_y" : rotation.y,
|
||||||
"rot_z" : rotation.z,
|
"rot_z" : rotation.z,
|
||||||
"health" : level_control.health
|
"crouched" : crouched,
|
||||||
|
"flashlight_on" : flashlight_on
|
||||||
}
|
}
|
||||||
return save_dict
|
return save_dict
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ var cycle_count
|
|||||||
@export var gun_name : String
|
@export var gun_name : String
|
||||||
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
@export_enum("Auto", "Single", "Burst") var fire_mode: int
|
||||||
@export var fov_zoom_amt = .98
|
@export var fov_zoom_amt = .98
|
||||||
|
@export var ads : bool = false
|
||||||
@export var recoil_amount : Vector3 = Vector3(1,.1,.1)
|
@export var recoil_amount : Vector3 = Vector3(1,.1,.1)
|
||||||
@export var recoil_speed_change : float = 4
|
@export var recoil_speed_change : float = 4
|
||||||
@export var max_ammo = 15
|
@export var max_ammo = 15
|
||||||
|
|||||||
Reference in New Issue
Block a user