meat_madness_redux/godot/effects/player/MovementSounds.gd

51 lines
1.1 KiB
GDScript

extends Node
var played_jump_sound = false
func jump():
var on_floor = $"../OnFootPhysics/Floor".is_on_floor
var jump_intent = $"../MovementInput".jump_intent
var falling_fast = $"../OnFootPhysics".is_falling_velocity_terminal()
if jump_intent and not on_floor and not played_jump_sound:
$Jump.play()
played_jump_sound = true
elif on_floor and played_jump_sound:
$Jump.stop()
$JumpLanding.play()
played_jump_sound = false
if not on_floor and falling_fast and not $FallingSound.playing:
$FallingSound.play()
$FallingSound.pitch_scale = rand_range(0.5, 1.2)
played_jump_sound = true
elif on_floor:
$FallingSound.stop()
func footsteps():
var on_floor = $"../OnFootPhysics/Floor".is_on_floor
var velocity = $"../MovementInput".input_xz
if not on_floor or velocity.length() == 0:
$Footsteps.stop()
return
if $Footsteps/Timer.time_left > 0.0:
return
$Footsteps.pitch_scale = rand_range(0.9, 1.1)
$Footsteps.play()
var is_sprinting = $"../MovementInput".sprinting
if is_sprinting:
$Footsteps/Timer.start(0.3)
else:
$Footsteps/Timer.start(0.5)
func _process(_delta):
if $"..".is_on_foot():
jump()
footsteps()