Trigger object SFX on physical impact with force-scaled volume#5
Open
dalision wants to merge 1 commit into
Open
Trigger object SFX on physical impact with force-scaled volume#5dalision wants to merge 1 commit into
dalision wants to merge 1 commit into
Conversation
Previously object impact SFX only played on click-to-grab — the samples in worlds/<slug>/output/<object>/sfx/ never fired from actual physics collisions (floor, wall, object-on-object). This wires onContactForce on each dynamic RigidBody and: - skips contacts below a force threshold so resting bodies stay quiet - throttles repeated impacts to one playback per 200ms per object - scales volume linearly with totalForceMagnitude, clamped to [0.15, 1.0] so taps stay audible and hard impacts hit max playRandomSfx now takes an optional volume arg so the click path keeps its existing full-volume behaviour with zero changes at the call site.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Object impact SFX in
worlds/<slug>/output/<object>/sfx/currently only play once, at the moment of click-to-grab (useObjectGrab.ts→playInteractionSfx). Actual physics collisions — object hitting the floor after a throw, smacking into a wall, knocking into another object — fire no sound at all.This makes the impact samples (recorded by the SFX pipeline specifically to sound like physical contact) feel disconnected from the physics: you can chuck a chair across the room, see it ragdoll, hear nothing on landing.
Change
SceneObject.tsxwires Rapier'sonContactForceon each dynamicRigidBody. Three guards keep the audio usable:IMPACT_FORCE_THRESHOLD = 8) — skips below-threshold contacts so an object resting on the ground stays quiet.IMPACT_THROTTLE_MS = 200) — at most one playback per object per 200ms, so a bouncing/sliding contact stream doesn't machine-gun the same sample.volume = totalForceMagnitude / IMPACT_FORCE_FULL_VOLUME, clamped to[0.15, 1.0]so light taps stay audible while hard impacts hit max.playRandomSfxgains an optionalvolumeargument (defaults to1) so the existing click-to-grab path is unchanged.Net diff: +17 / -2 in one file, no new dependencies.
Verification
bun --cwd=app run typecheckpassesNotes