death camera mostly working
This commit is contained in:
@@ -56,6 +56,7 @@ var bullet_destination
|
||||
var gun_fire_pitch_starting
|
||||
var current_weapon_index
|
||||
var recoiling = false
|
||||
var dead = false
|
||||
|
||||
# Slow Down Variables
|
||||
const SLOWSPEED = .2
|
||||
@@ -98,136 +99,139 @@ func _unhandled_input(event):
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity.y -= gravity * delta
|
||||
else:
|
||||
double_jump = true
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor() and !is_climbing:
|
||||
velocity.y += JUMP_VELOCITY
|
||||
elif Input.is_action_just_pressed("jump") and double_jump == true and !is_climbing:
|
||||
velocity.y += JUMP_VELOCITY
|
||||
double_jump = false
|
||||
if !dead:
|
||||
|
||||
# Handle Sprint
|
||||
if Input.is_action_pressed("sprint") and is_on_floor():
|
||||
speed = SPRINT_SPEED
|
||||
else:
|
||||
speed = WALK_SPEED
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
var direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
if is_on_floor() and !is_climbing:
|
||||
if direction:
|
||||
velocity.x = direction.x * speed
|
||||
velocity.z = direction.z * speed
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity.y -= gravity * delta
|
||||
else:
|
||||
double_jump = true
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor() and !is_climbing:
|
||||
velocity.y += JUMP_VELOCITY
|
||||
elif Input.is_action_just_pressed("jump") and double_jump == true and !is_climbing:
|
||||
velocity.y += JUMP_VELOCITY
|
||||
double_jump = false
|
||||
|
||||
# Handle Sprint
|
||||
if Input.is_action_pressed("sprint") and is_on_floor():
|
||||
speed = SPRINT_SPEED
|
||||
else:
|
||||
speed = WALK_SPEED
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
var direction = (self.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
if is_on_floor() and !is_climbing:
|
||||
if direction:
|
||||
velocity.x = direction.x * speed
|
||||
velocity.z = direction.z * speed
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5)
|
||||
elif is_climbing:
|
||||
gravity = 0.0
|
||||
if direction:
|
||||
velocity.y = -direction.z * speed * .75
|
||||
velocity.x = direction.x * speed * .3
|
||||
else:
|
||||
velocity.y = lerp(velocity.y, -direction.z * speed, delta * 6.5)
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5)
|
||||
elif is_climbing:
|
||||
gravity = 0.0
|
||||
if direction:
|
||||
velocity.y = -direction.z * speed * .75
|
||||
velocity.x = direction.x * speed * .3
|
||||
else:
|
||||
velocity.y = lerp(velocity.y, -direction.z * speed, delta * 6.5)
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
|
||||
else:
|
||||
velocity.x = lerp(velocity.x, direction.x * speed, delta * 6.5)
|
||||
velocity.z = lerp(velocity.z, direction.z * speed, delta * 6.5)
|
||||
|
||||
# Head bob
|
||||
t_bob += delta * velocity.length() * float(is_on_floor())
|
||||
camera.transform.origin = _headbob(t_bob)
|
||||
|
||||
# FOV
|
||||
var velocity_clamped = clamp(velocity.length(), 0.5, SPRINT_SPEED * 2)
|
||||
var target_fov = BASE_FOV + FOV_CHANGE * velocity_clamped
|
||||
camera.fov = lerp(camera.fov, target_fov, delta * 8)
|
||||
|
||||
# Land sound
|
||||
|
||||
|
||||
# Game Speed
|
||||
if Input.is_action_pressed("slow_down") and remaining_stamina >0:
|
||||
Engine.time_scale = lerp(0, 1, SLOWSPEED)
|
||||
gun.random_spread_amt = 0
|
||||
AudioServer.set_bus_effect_enabled(0,0,true)
|
||||
camera.fov = lerp(camera.fov, camera.fov * gun.fov_zoom_amt, delta * 100)
|
||||
if sensitivity_shift == true:
|
||||
SENSITIVITY = lerp(SENSITIVITY, SENSITIVITY * .998, delta * 100)
|
||||
if remaining_stamina >0:
|
||||
remaining_stamina -= 1000 * delta
|
||||
else:
|
||||
Engine.time_scale = 1
|
||||
gun.random_spread_amt = gun.random_spread_start
|
||||
AudioServer.set_bus_effect_enabled(0,0,false)
|
||||
if sensitivity_shift == true:
|
||||
camera.fov = lerp(camera.fov, BASE_FOV, delta * .5)
|
||||
SENSITIVITY = start_sensitivity
|
||||
if remaining_stamina < MAX_STAMINA:
|
||||
remaining_stamina += STAMINA_DRAIN * delta
|
||||
elif remaining_stamina > MAX_STAMINA * 1.01:
|
||||
remaining_stamina -= (STAMINA_DRAIN)/2 * delta
|
||||
|
||||
# Reloading
|
||||
if Input.is_action_just_pressed("reload"):
|
||||
gun.reload(delta)
|
||||
|
||||
if Input.is_action_pressed("inspect") and !gun.anim_player.is_playing():
|
||||
gun.anim_player.play("inspect")
|
||||
|
||||
# Shooting & fire modes
|
||||
if Input.is_action_pressed("shoot"):
|
||||
gun.shoot(delta)
|
||||
|
||||
if Input.is_action_just_released("shoot"):
|
||||
gun.cycle_count = gun.cycle_count_start
|
||||
|
||||
# Gun folding out of the way
|
||||
if gun_ray.is_colliding() and !gun_ray.get_collider().is_in_group("player"):
|
||||
#check distance to wall later ?
|
||||
gun.rotation = lerp(gun.rotation, Vector3(1, -1, -.25), delta * 10)
|
||||
gun.position = lerp(gun.position, Vector3(gun.start_position.x+.25,gun.start_position.y +.2,gun.start_position.z +.6),(delta*10))
|
||||
gun_folded = true
|
||||
elif !gun_ray.is_colliding():
|
||||
gun.rotation = lerp(gun.rotation, gun.start_rotation,delta*7)
|
||||
gun.position = lerp(gun.position, gun.start_position,delta*7)
|
||||
gun_folded = false
|
||||
|
||||
#Weapon Swap Up
|
||||
if Input.is_action_just_pressed("scroll_up") and !gun.anim_player.is_playing():
|
||||
if level_control.held_guns.size() > 1:
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(level_control.current_gun_index + 1)
|
||||
#Weapon Swap Down
|
||||
if Input.is_action_just_pressed("scroll_down") and !gun.anim_player.is_playing():
|
||||
if level_control.held_guns.size() > 1:
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(level_control.current_gun_index - 1)
|
||||
|
||||
|
||||
#interact button
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
if interact_ray.is_colliding(): # and !interact_ray.get_collider().is_in_group("interact"):
|
||||
var body = interact_ray.get_collider()
|
||||
body.get_parent().interact()
|
||||
# Head bob
|
||||
t_bob += delta * velocity.length() * float(is_on_floor())
|
||||
camera.transform.origin = _headbob(t_bob)
|
||||
|
||||
# FOV
|
||||
var velocity_clamped = clamp(velocity.length(), 0.5, SPRINT_SPEED * 2)
|
||||
var target_fov = BASE_FOV + FOV_CHANGE * velocity_clamped
|
||||
camera.fov = lerp(camera.fov, target_fov, delta * 8)
|
||||
|
||||
# Land sound
|
||||
|
||||
|
||||
# Game Speed
|
||||
if Input.is_action_pressed("slow_down") and remaining_stamina >0:
|
||||
Engine.time_scale = lerp(0, 1, SLOWSPEED)
|
||||
gun.random_spread_amt = 0
|
||||
AudioServer.set_bus_effect_enabled(0,0,true)
|
||||
camera.fov = lerp(camera.fov, camera.fov * gun.fov_zoom_amt, delta * 100)
|
||||
if sensitivity_shift == true:
|
||||
SENSITIVITY = lerp(SENSITIVITY, SENSITIVITY * .998, delta * 100)
|
||||
if remaining_stamina >0:
|
||||
remaining_stamina -= 1000 * delta
|
||||
else:
|
||||
Engine.time_scale = 1
|
||||
gun.random_spread_amt = gun.random_spread_start
|
||||
AudioServer.set_bus_effect_enabled(0,0,false)
|
||||
if sensitivity_shift == true:
|
||||
camera.fov = lerp(camera.fov, BASE_FOV, delta * .5)
|
||||
SENSITIVITY = start_sensitivity
|
||||
if remaining_stamina < MAX_STAMINA:
|
||||
remaining_stamina += STAMINA_DRAIN * delta
|
||||
elif remaining_stamina > MAX_STAMINA * 1.01:
|
||||
remaining_stamina -= (STAMINA_DRAIN)/2 * delta
|
||||
|
||||
# Reloading
|
||||
if Input.is_action_just_pressed("reload"):
|
||||
gun.reload(delta)
|
||||
|
||||
if Input.is_action_pressed("inspect") and !gun.anim_player.is_playing():
|
||||
gun.anim_player.play("inspect")
|
||||
|
||||
# Shooting & fire modes
|
||||
if Input.is_action_pressed("shoot"):
|
||||
gun.shoot(delta)
|
||||
|
||||
|
||||
#quit game and eventually go to menu
|
||||
if Input.is_action_just_pressed("escape"):
|
||||
get_tree().quit()
|
||||
|
||||
if level_control.health <= 0:
|
||||
level_control.die()
|
||||
|
||||
move_and_slide()
|
||||
weapon_tilt(input_dir.x, delta)
|
||||
weapon_sway(delta)
|
||||
weapon_bob(velocity.length(), delta)
|
||||
if Input.is_action_just_released("shoot"):
|
||||
gun.cycle_count = gun.cycle_count_start
|
||||
|
||||
# Gun folding out of the way
|
||||
if gun_ray.is_colliding() and !gun_ray.get_collider().is_in_group("player"):
|
||||
#check distance to wall later ?
|
||||
gun.rotation = lerp(gun.rotation, Vector3(1, -1, -.25), delta * 10)
|
||||
gun.position = lerp(gun.position, Vector3(gun.start_position.x+.25,gun.start_position.y +.2,gun.start_position.z +.6),(delta*10))
|
||||
gun_folded = true
|
||||
elif !gun_ray.is_colliding():
|
||||
gun.rotation = lerp(gun.rotation, gun.start_rotation,delta*7)
|
||||
gun.position = lerp(gun.position, gun.start_position,delta*7)
|
||||
gun_folded = false
|
||||
|
||||
#Weapon Swap Up
|
||||
if Input.is_action_just_pressed("scroll_up") and !gun.anim_player.is_playing():
|
||||
if level_control.held_guns.size() > 1:
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(level_control.current_gun_index + 1)
|
||||
#Weapon Swap Down
|
||||
if Input.is_action_just_pressed("scroll_down") and !gun.anim_player.is_playing():
|
||||
if level_control.held_guns.size() > 1:
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(level_control.current_gun_index - 1)
|
||||
|
||||
|
||||
#interact button
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
if interact_ray.is_colliding(): # and !interact_ray.get_collider().is_in_group("interact"):
|
||||
var body = interact_ray.get_collider()
|
||||
body.get_parent().interact()
|
||||
|
||||
|
||||
#quit game and eventually go to menu
|
||||
if Input.is_action_just_pressed("escape"):
|
||||
get_tree().quit()
|
||||
|
||||
if level_control.health <= 0:
|
||||
level_control.die()
|
||||
|
||||
move_and_slide()
|
||||
weapon_tilt(input_dir.x, delta)
|
||||
weapon_sway(delta)
|
||||
weapon_bob(velocity.length(), delta)
|
||||
|
||||
func _headbob(time) -> Vector3:
|
||||
var pos = Vector3.ZERO
|
||||
|
||||
Reference in New Issue
Block a user