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

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).

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


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 player vehicle through a state machine:

  1. Idle - Waiting for reverse driving at speed (≥ 8 m/s)
  2. Triggered - Vehicle is driving backward (direction vector · velocity < -0.96). Records the backing direction
  3. Completion check - While triggered, checks if the vehicle now drives forward (dot > 0.96) AND the forward direction is nearly opposite to the original backing direction (dot < -0.90)
  4. Timeout - If more than 4 seconds pass since the last backward detection, the attempt is cancelled

Constants

ConstantValueDescription
THRESHOLD0.96Dot product threshold for forward/backward alignment
THRESHOLDUTURN-0.90Dot product threshold for 180° turn completion
REFRESH1Minimum seconds between backing direction updates
TIMEOUT4Seconds before a triggered attempt expires
Minimum speed8 m/s~29 km/h minimum to begin detection
M.onExtensionLoaded()-
M.onVehicleResetted(vid)-
M.onVehicleSwitched(oldid, newid, player)-
M.workload(v , vid , dtSim)-

Metric Recorded

On successful J-turn detection:

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

How It Works

  1. The workload function is registered with gameplay_statistic.addSchedule() during module load
  2. Each frame (round-robin), checks the player vehicle's velocity vs direction vectors
  3. When the vehicle drives backward fast enough, records the backing direction and enters triggered state
  4. If the vehicle subsequently drives forward in the opposite direction (within timeout), records a J-turn
  5. Vehicle resets and switches cancel any in-progress detection

Usage Example

-- This module is auto-loaded by gameplay_statistic
-- To check J-turn count:
local jturnData = gameplay_statistic.metricGet("vehicle/jturn", true)
if jturnData then
  log("I", "", "J-turns: " .. jturnData.value)
end

See Also

  • gameplay/statisticModules/watchRollover - Rollover Detection - Related reference
  • Gameplay Systems Guide - Guide

Sites Zone

Class representing a 2D polygon zone with optional top/bottom bounding planes. Used for defining areas (parking zones, restricted areas, etc.) within the sites system.

Rollover Detection

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

On this page

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