Coupler Camera Modifier
Adjusts orbit camera distance and target when two vehicles are coupled (e.g. truck + trailer), centering the view between them. Automatically restores original camera settings on detach or when vehicl
Adjusts orbit camera distance and target when two vehicles are coupled (e.g. truck + trailer), centering the view between them. Automatically restores original camera settings on detach or when vehicles move apart.
Public API
| Function | Signature | Description |
|---|---|---|
M.checkForTrailer | (objId1, objId2) → bool | Returns true if the player vehicle is one of the two objects and they are within coupling distance (1–15 m). |
M.onCouplerAttached | (objId1, objId2) | Hook: validates trailer pair, saves original camera distances, locks orbit cameras, and sets combined distance. |
M.onCouplerDetached | (objId1, objId2) | Hook: restores original orbit camera distances and clears coupling state. |
M.onVehicleSpawned | (vehId) | Hook: if a coupled vehicle is respawned/replaced, triggers detach cleanup. |
M.onUpdate | () | Per-frame: recalculates mean reference position between coupled vehicles and feeds it to core_camera. Auto-detaches when distance exceeds sum of original distances. |
M.onSerialize | () → table | Saves coupling state for hot-reload. |
M.onDeserialized | (data) | Restores coupling state from serialized data. |
How It Works
- Attach -
onCouplerAttachedvalidates the pair viacheckForTrailer, then locks both orbit cameras to a shared distance(d1+d2)/1.5+1. - Frame update -
onUpdatecomputes a midpoint between both vehicles' reference nodes and offsets, then callscore_camera.setRefso the orbit pivots around the combo. - Detach / distance - if vehicles separate beyond original distance sum, or
onCouplerDetachedfires, cameras unlock and revert.
Usage Example
-- Typically driven by engine hooks; manual test:
if core_couplerCameraModifier.checkForTrailer(truckId, trailerId) then
log('I', 'test', 'Trailer detected, camera will auto-adjust')
endKey Internals
- Uses
core_camera.getCameraDataById(id).orbitfor per-vehicle orbit data. - Reference nodes (
ref,left,back) build a local coordinate frame for offset calculations. detachedflag prevents redundant restore calls.
Core Command Handler
Handles `beamng:` URL scheme commands for mod management, map loading, toolchain, debugger control, and other async tasks triggered via protocol URLs or startup arguments.
Devices (RGB Peripherals)
Manages RGB lighting on supported peripherals (e.g. keyboards, mice). Sets the BeamNG orange brand color when switching to non-drivable entities (unicycle, props, no vehicle) and resets to vehicle-dri