Audio: mood music, ambience, sound effects and creature voices (Kenney CC0 + synthesised); protocol 13
This commit is contained in:
@@ -103,3 +103,42 @@ func _physics_process(delta: float) -> void:
|
||||
velocity.z = move_toward(velocity.z, 0, current_speed)
|
||||
|
||||
move_and_slide()
|
||||
_footsteps(delta, swimming)
|
||||
|
||||
# --- footsteps (sfx.gd) ------------------------------------------------------------
|
||||
|
||||
const STRIDE := 1.9 ## metres between footsteps (walking; a little longer sprinting)
|
||||
var _stride := 0.0
|
||||
|
||||
## A footstep every stride on the ground, by what's underfoot (a floor
|
||||
## piece's wood or stone, snow up high or while it's snowing, else grass);
|
||||
## a stroke now and then while swimming. Only you hear your own.
|
||||
func _footsteps(dt: float, swimming: bool) -> void:
|
||||
var v := Vector2(velocity.x, velocity.z).length()
|
||||
if v < 1.0 or not (is_on_floor() or swimming):
|
||||
_stride = minf(_stride, STRIDE * 0.6) # (the first step after stopping comes soon)
|
||||
return
|
||||
_stride += v * dt
|
||||
var gap := STRIDE * (1.2 if v > speed + 0.5 else 1.0) * (1.6 if swimming else 1.0)
|
||||
if _stride < gap:
|
||||
return
|
||||
_stride = 0.0
|
||||
Sfx.me("swim" if swimming else step_sound())
|
||||
|
||||
func step_sound() -> String:
|
||||
var q := PhysicsRayQueryParameters3D.create(global_position + Vector3(0, 0.3, 0), global_position - Vector3(0, 0.5, 0))
|
||||
q.exclude = [get_rid()]
|
||||
var hit := get_world_3d().direct_space_state.intersect_ray(q)
|
||||
var c: Object = hit.get("collider")
|
||||
# (a piece's collider is its body or one of its children)
|
||||
for _i in range(3):
|
||||
if not (c is Node):
|
||||
break
|
||||
if (c as Node).is_in_group("piece"):
|
||||
return "step_stone" if String((c as Node).get("item_id")).contains("stone") else "step_wood"
|
||||
c = (c as Node).get_parent()
|
||||
var w: Node = get_parent()
|
||||
var wx: Node = w.get("weather") if w != null else null
|
||||
if wx != null and (String(wx.get("state")) in ["snow", "blizzard"] or global_position.y > float(wx.get("snowline")) - 1.0):
|
||||
return "step_snow"
|
||||
return "step_grass"
|
||||
|
||||
Reference in New Issue
Block a user