Lesson 11
The finish line for 3D. We add positional pickup sounds, a bit of ambience, and export a playable build. By the end you have a complete GlitchFall to share.
3D games can place sound in space with AudioStreamPlayer3D — a pickup on your left sounds like it's on your left. Add one to the Fragment.
fragment.tscn. Add a child AudioStreamPlayer3D named PickupSound. Drag a short chime .ogg/.wav into its Stream slot.Play the sound before freeing
If you queue_free() the fragment immediately, its audio player dies before the sound finishes. Two clean options: (a) play the sound, then free after a short delay via the tween callback; or (b) detach the sound. Simplest is to reparent the sound to Main or delay the free — shown below.
Adjust the pickup so the sound survives the fragment. In fragment.gd:
@onready var pickup_sound: AudioStreamPlayer3D = $PickupSound
func _play_pickup_and_free() -> void:
set_deferred("monitoring", false)
# Move the sound player to the parent so it outlives this node.
if pickup_sound and pickup_sound.stream:
pickup_sound.reparent(get_parent())
pickup_sound.play()
# Auto-free the reparented sound when it finishes.
pickup_sound.finished.connect(pickup_sound.queue_free)
var tw: Tween = create_tween()
tw.tween_property(self, "scale", scale * 1.8, 0.15)
tw.tween_callback(queue_free)reparent keeps world position
reparent() moves a node to a new parent while preserving its world transform — the sound keeps playing from where the fragment was. The finished signal then cleans it up. No orphaned nodes.
Main named Ambience. Assign a looping pad/drone stream.2D vs 3D audio players
AudioStreamPlayer = non-positional (music, UI, ambience). AudioStreamPlayer3D = positional (world sounds that pan and attenuate with distance). Use the right one for the job.
index.html and support files can be hosted — including on TeqStudy.Web export + mouse capture
Browsers only allow mouse capture after a user click. On web, the pointer locks when the player first clicks the canvas — that's expected behavior, not a bug. Add a 'click to start' hint for web exports.
GlitchFall complete
A lit world, a physics character, a third-person camera, collectibles, hazards with respawn, a gated exit, a HUD and win screen, glitch atmosphere, positional sound, and an export. GlitchFall is a complete 3D adventure built by example.
Checkpoint — expected state