RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
Gameplay AchievementGameplay CityDiscoverForce FieldGarage ModeMarker InteractionParking SystemGameplay Playmode MarkersGameplay PoliceGameplay RallyGameplay Rally LoopGameplay Raw POIsGameplay Skidpad TestSpeed Trap LeaderboardsSpeed Traps and CamerasGameplay StatisticsTaxi Ride SystemTraffic SystemVehicle PerformanceWalking
Crash DetectionDamage AssessmentGround ContactSorted List

UI

Resources

BeamNG Game Engine Lua Cheat SheetGE Developer RecipesMCP Server Setup

// RLS.STUDIOS=true

Premium Mods for BeamNG.drive. Career systems, custom vehicles, and immersive gameplay experiences.

Index

HomeProjectsPatreon

Socials

DiscordPatreon (RLS)Patreon (Vehicles)

© 2026 RLS Studios. All rights reserved.

Modding since 2024

API ReferenceGE Extensionsgameplayutil

Crash Detection

Reference for `gameplay_util_crashDetection`, which tracks vehicle damage in real-time to detect crashes and individual impacts. Provides event hooks for crash start/end and impact start/end, with acc

Reference for gameplay_util_crashDetection, which tracks vehicle damage in real-time to detect crashes and individual impacts. Provides event hooks for crash start/end and impact start/end, with acceleration-based damage thresholds.


Module Exports (M)

Vehicle Tracking

FunctionSignatureDescription
addTrackedVehicleById(vehId, crashSettings?, owner?)Start tracking a vehicle for crash events
removeTrackedVehicleById(vehId)Stop tracking a vehicle
isVehCrashing(vehId) → boolCheck if a tracked vehicle is currently crashing
isVehTracked(vehId) → boolCheck if a vehicle is being tracked
resetCrashData(vehId)Reset all crash/impact data for a vehicle

Debug

FunctionSignatureDescription
setDebug(bool)Toggle debug visualization (spheres, ImGui graphs)

Extension Lifecycle

ExportSignatureDescription
dependencies{"gameplay_util_damageAssessment"}Required extension dependency
onUpdate(dtReal, dtSim, dtRaw)Per-frame crash state machine tick; processes damage deltas
onSerialize() → tableSerialize tracked vehicle settings for save
onDeserialized(data)Restore tracked vehicles from saved state
onVehicleDestroyed(vehId)Cleanup tracking data when vehicle is removed

Hooks Fired

HookDataDescription
onVehicleCrashStarted{vehId, vehImpactPos, vehImpactSpeed}First impact of a crash
onNewImpactStarted{newImpactData}Subsequent impact within same crash
onVehicleCrashEnded{impacts, sanitizedData, totalDamage, vehId}Crash fully ended

Internals

Crash Settings

SettingDefaultDescription
minAccel0Min acceleration for threshold scaling
maxAccel100Max acceleration for threshold scaling
minDamage150Damage threshold at max acceleration
maxDamage5000Damage threshold at zero acceleration
verticallyUnweightedfalseReduce vertical acceleration weight (removes road bumps)
minVelocity1 m/sMinimum velocity to sustain a crash
groupImpactsDist1mMax distance between frames to group as same impact
enableImpactLocationDatafalseEnable damage section analysis per impact
M.addTrackedVehicleById(vehId_, crashSettings, owner)-
M.dependenciesvalue-
M.isVehCrashing(vehId)-
M.isVehTracked(vehId)-
M.onDeserialized(data)-
M.onSerialize()-
M.onUpdate(dtReal, _dtSim)-
M.onVehicleDestroyed(vehId)-
M.removeTrackedVehicleById(vehId)-
M.resetCrashData(vehId)-
M.setDebug(_debug)-

Detection Pipeline (per frame)

  1. updateAccelData - Tracks two points (front/rear) on the vehicle, computing smoothed acceleration and jerk
  2. logicDuringCrash - Increments crash timer if crashing or might-be-crashing
  3. managedImpactAndDetectImpacts - Compares damage to acceleration-scaled threshold:
    • Below threshold → preImpactData (stored in case it becomes a real impact)
    • Above threshold → currentImpactData (confirmed impact)
  4. checkIfPreImpactEnded - Clears pre-impact data if vehicle moved away
  5. checkIfImpactEnded - Finalizes impact when vehicle distance exceeds groupImpactsDist or velocity drops
  6. checkIfCrashEnded - Ends crash if stopCrashDelay (1.8s) elapsed since last impact or velocity too low

Impact Data Structure

{
  frameDamages = {
    {time, newDamage, newDamageSum, vehPos, speed, touchedVehIds, isAboveDamageThreshold},
    ...
  },
  touchedVehIds = {[id] = {name = "pickup"}},
  averagePos = vec3,
  totalDamage = number,
  impactSpeed = number,
  startingDamageState = table,  -- if enableImpactLocationData
  damageStateDiff = table       -- textual damage locations
}

Crash End Data

{
  vehId = number,
  impacts = { impact1, impact2, ... },
  sanitizedData = {
    touchedVehIds = {[id] = {name = "..."}},
    initialImpactPos = vec3,
    initialImpactSpeed = number,
  },
  totalDamage = number,
}

How It Works

The system uses a dynamic threshold that scales with jerk (rate of acceleration change). High jerk → lower damage threshold → more sensitive impact detection. This prevents road bumps from triggering false crashes while still catching real collisions.

Impacts are grouped spatially - if the vehicle stays within groupImpactsDist of the last frame damage, it's part of the same impact. Multiple impacts form a crash, which ends after 1.8s of no new impacts.


Usage Example

-- Start tracking player vehicle
local vehId = be:getPlayerVehicleID(0)
gameplay_util_crashDetection.addTrackedVehicleById(vehId, {
  maxDamage = 3000,
  enableImpactLocationData = true,
}, "myMod")

-- Listen for crash events
local function onVehicleCrashEnded(data)
  log("I", "", string.format("Crash! %d damage, %d impacts", data.totalDamage, #data.impacts))
end

-- Check if crashing right now
if gameplay_util_crashDetection.isVehCrashing(vehId) then
  -- vehicle is mid-crash
end

See Also

  • gameplay/util/damageAssessment - Vehicle Damage Location Assessment - Related reference
  • gameplay/util/groundContact - Ground Contact Detection - Related reference
  • gameplay/util/sortedList - Sorted Object List Container - Related reference
  • Gameplay Systems Guide - Guide

Suspect Traffic Role

Reference for the `suspect` traffic role, which marks a vehicle as a wanted suspect that police will chase. Manages the transition from watched → wanted → fleeing → arrested states.

Damage Assessment

Reference for `gameplay_util_damageAssessment`, which provides spatial damage analysis by dividing a vehicle's bounding box into a 3×3×3 grid (27 sections) and determining which body regions sustained

On this page

Module Exports (M)Vehicle TrackingDebugExtension LifecycleHooks FiredInternalsCrash SettingsDetection Pipeline (per frame)Impact Data StructureCrash End DataHow It WorksUsage ExampleSee Also