Torque Valley: Driving, Drift and Crash Sandbox
README.md
EngineVoice
The sound of a car. Put it on a car's chassis entity, the one that carries the driving contract's car.* named values, and it plays the engine, gear changes, rev limiter, turbo, tyre skids and crashes from those values. It needs no sibling component: any entity that writes car.rpm, car.load and the rest gets a voice, a torqueCars car, another car kit, or the EngineVoiceDemo stand-in.
It spawns local child entities, each with a spatial Audio source at doppler = 1, so passing cars drop in pitch:
- six engine layers, three rpm bands times on-load and off-load. They crossfade by rpm (equal power, in log rpm) and by
car.load, and each is pitched torpm / band reference rpm; - an aux layer: the turbo whistle that follows
car.boost(turbo, diesel) or the inverter whine (electric); - a skid loop whose volume follows
car.skidand whose clip changes withcar.surfaceId: tarmac squeal, gravel crunch, soft scrub; - a one-shot host for gear changes (
car.shiftCount), overrun pops, blow-off on lift, limiter stutter pops and crash crunches (car.impactCount, scaled bycar.impactSpeed).
The values replicate and the component runs on every peer, so every player hears every car.
Fields
| field | default | meaning |
|---|---|---|
voice | auto | auto follows car.voiceId. Set a name to force a voice: four, v8, v12, diesel, rotary, turbo, electric, kart. It can be changed live. |
volume | 1 | multiplier for everything this car sounds |
maxDistance | 160 | metres to silence |
shiftStyle | auto | auto reads the Car component's gearbox mode, falling back to the voice's default; or manual, sequential, automatic, none |
skids, crashes | true | turn those sounds off |
doppler | 1 | Doppler scale on every source |
:mix() returns what the voice is doing this frame: the voice, the smoothed rpm, load and boost, the band weights, the on-load and off-load gains, the level, the skid level and kind, and the ids of its sources. Read those ids with audio.voice(id).
car.component.add("EngineVoice") -- voice from car.voiceId
car.component.get("EngineVoice").voice = "rotary" -- switch it live
print(car.component.get("EngineVoice"):mix().bands[2])