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
J-Turn DetectionRollover Detection

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 ExtensionsgameplaystatisticModules

Rollover Detection

Reference for `gameplay_statisticModules_watchRollover`, a statistic submodule that detects vehicle rollovers (flipping upside-down and back upright).

Reference for gameplay_statisticModules_watchRollover, a statistic submodule that detects vehicle rollovers (flipping upside-down and back upright).


Module Exports (M)

FunctionSignatureDescription
workload(vehObj, vehId, dtSim)Per-frame detection function called by the statistic scheduler

Hooks (Event Handlers)

HookDescription
onExtensionLoadedNo-op placeholder
onVehicleResettedCancels detection if tracked vehicle resets
onVehicleSwitchedCancels detection on vehicle switch

Internals

Detection Algorithm

The module tracks the vehicle's up-vector Z component through a state machine:

  1. Upright - Vehicle's up-vector Z > 0.7 (roughly right-side-up). Records the upright timestamp
  2. Roof - Vehicle's up-vector Z < -0.7 (upside-down) AND moving more sideways than forward (|dir·vel| < |right·vel|). Enters triggered state
  3. Completion - When upright again after being on the roof, checks that roof was within 4s and upright was within 8s. If both pass → rollover counted
  4. Timeout - If conditions aren't met within timeouts, the attempt resets

Constants

ConstantValueDescription
THRESHOLD0.7Up-vector Z threshold for upright/roof detection
REFRESH1Minimum seconds between state timestamp updates
TIMEOUT4Seconds timeout for roof-to-upright transition
M.onExtensionLoaded()-
M.onVehicleResetted(vid)-
M.onVehicleSwitched(oldid, newid, player)-
M.workload(v , vid , dtSim)-

Metric Recorded

On successful rollover detection:

gameplay_statistic.metricAdd("vehicle/rollover", 1)

How It Works

  1. The workload function is registered with gameplay_statistic.addSchedule() during module load
  2. Each frame (round-robin), computes the vehicle's up, direction, velocity, and right vectors
  3. Tracks transitions between upright → roof → upright within time windows
  4. The sideways velocity check prevents false positives from driving on steep slopes
  5. Vehicle resets and switches cancel any in-progress detection

Usage Example

-- This module is auto-loaded by gameplay_statistic
-- To check rollover count:
local rollData = gameplay_statistic.metricGet("vehicle/rollover", true)
if rollData then
  log("I", "", "Rollovers: " .. rollData.value)
end

See Also

  • gameplay/statisticModules/watchJturn - J-Turn Detection - Related reference
  • Gameplay Systems Guide - Guide

J-Turn Detection

Reference for `gameplay_statisticModules_watchJturn`, a statistic submodule that detects J-turn maneuvers (reversing at speed, then spinning 180° to drive forward).

Base Traffic Role

Reference for `gameplay_traffic_baseRole`, the base class for all traffic vehicle driver roles. Provides personality generation, action management, flowgraph support, and common utility methods inheri

On this page

Module Exports (M)Hooks (Event Handlers)InternalsDetection AlgorithmConstantsMetric RecordedHow It WorksUsage ExampleSee Also