Sensors Module Reference
Module defined in `lua/vehicle/sensors.lua`. Provides real-time physical sensor data (G-forces, angular velocities, orientation) with optional temporal smoothing. Used by AI for driving decisions, by the UI for G-force meters, and by extensions for impact detection and stability monitoring. Reads directly from the C++ physics engine via FFI for maximum performance.
Module defined in lua/vehicle/sensors.lua. Provides real-time physical sensor data (G-forces, angular velocities, orientation) with optional temporal smoothing. Used by AI for driving decisions, by the UI for G-force meters, and by extensions for impact detection and stability monitoring. Reads directly from the C++ physics engine via FFI for maximum performance.
See Also
- Electrics: For values derived from sensors.
- CommonPatterns: For impact detection recipes using sensors.
State Fields
| Variable | Description |
|---|---|
ffiSensors | Raw FFI pointer to engine sensor data. Fields: gx, gy, gz: Acceleration. yawAngVel, pitchAngVel, rollAngVel: Angular velocities. sensorX, sensorY, sensorZ: Absolute orientation vectors. |
gx, gy, gz | Instantaneous G-forces in the vehicle's local frame. |
gx2, gy2, gz2 | Smoothed G-forces (filter rate 7). Use these for UI or logic that needs stable acceleration data. |
Public API
| Function | Signature | Description |
|---|---|---|
init | () | Obtains FFI pointer and resets smoothers. |
reset | () | Resets temporal filters. |
updateGFX | (dt) | Updates instantaneous and smoothed physical values. |
Usage Example
-- Read instantaneous G-forces (vehicle-local frame)
local lateralG = sensors.gx -- Side-to-side
local longitudinalG = sensors.gy -- Front-to-back (braking/accel)
local verticalG = sensors.gz -- Up-down (bumps, jumps)
-- Use smoothed values for UI or stable logic
local totalG = math.sqrt(sensors.gx2^2 + sensors.gy2^2 + sensors.gz2^2) / 9.81
-- High-performance FFI access for physics-step code
local s = sensors.ffiSensors
local yawRate = s.yawAngVel -- rad/sScriptAI Module Reference
Module defined in `lua/vehicle/scriptai.lua`. Handles high-fidelity path recording and playback for cinematic sequences and scripted behavior.
Sounds Module Reference
Module defined in `lua/vehicle/sounds.lua`. This module interfaces with the game's audio engine to handle impacts, scrapes, wind, tires, and the JBeam soundscape. It also provides a wrapper for manage