Added voice audio

This commit is contained in:
2024-02-16 15:30:29 +01:00
parent 91f5167d6a
commit 89d730f0ae
13 changed files with 86 additions and 49 deletions

View File

@ -0,0 +1,49 @@
class_name FootstepsComponent
extends Node
@export var skeleton: Skeleton3D
@export var movement: MovementComponent
@export var footsteps: AudioStreamRandomizer
@export var step_threshold := 0.1
const feet_names := ["LeftFoot", "RightFoot"]
var feet: Array[Foot] = []
func _ready():
for foot_name in feet_names:
var foot = Foot.new()
foot.bone_name = foot_name
foot.bone_id = skeleton.find_bone(foot_name)
foot.audio = get_node(foot_name)
foot.position = skeleton.to_global(skeleton.get_bone_global_pose(foot.bone_id).origin)
foot.attachment = BoneAttachment3D.new()
foot.attachment.bone_name = foot_name
foot.attachment.bone_idx = foot.bone_id
foot.audio.reparent(foot.attachment)
skeleton.add_child(foot.attachment)
feet.append(foot)
func _process(delta: float):
for foot in feet:
var old_position := foot.position
foot.position = skeleton.to_global(skeleton.get_bone_global_pose(foot.bone_id).origin)
foot.velocity = (foot.position - old_position) / delta
if foot.position.y > step_threshold:
continue
if foot.velocity.y > 0:
continue
if foot.velocity.length_squared() < 1.0:
continue
if foot.audio.playing && foot.audio.get_playback_position() < 0.3:
continue
play(foot.audio)
func play(audio_player: AudioStreamPlayer3D):
audio_player.stream = footsteps
audio_player.play()