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
Base Traffic RoleTraffic UtilitiesTraffic Vehicle

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 Extensionsgameplaytraffic

Traffic Vehicle

Reference for the traffic vehicle class (`gameplay/traffic/vehicle`), instantiated for each vehicle in the traffic system. Manages per-vehicle state including position tracking, damage detection, coll

Reference for the traffic vehicle class (gameplay/traffic/vehicle), instantiated for each vehicle in the traffic system. Manages per-vehicle state including position tracking, damage detection, collision handling, driving tracking, offense detection, respawning, and role delegation.


Constructor

local veh = require('gameplay/traffic/vehicle')({id = vehicleId})

Returns the vehicle object if valid (car/truck/automation/traffic/proptraffic/player type), or nil if invalid.


Key Properties

PropertyTypeDescription
idnumberVehicle object ID
pos, dirVec, velvec3Position, direction, velocity (from map.objects)
speednumberCurrent speed (m/s)
damagenumberCurrent damage value
statestring"reset", "active", "fadeIn", "fadeOut", "queued", "locked"
roleobjectCurrent driver role (standard/police/suspect/empty)
roleNamestringName of current role
pursuittablePursuit state (mode, score, offenses, timers)
trackingtableDriving tracking (speed, direction, signals, collisions)
respawntableRespawn parameters (spawnValue, activeRadius, etc.)
isAiboolWhether vehicle has AI enabled
modelstringJBeam model name
modelNamestringDisplay name (Brand + Name)

Key Methods

State Management

MethodDescription
resetAll()Resets pursuit, tracking, values, and collisions
resetPursuit()Clears pursuit state to mode 0
resetTracking()Resets driving score, direction score, speed score
resetValues()Resets respawn parameters and queued functions
resetElectrics()Turns off lightbar, warning signal, horn

Role & AI

MethodDescription
setRole(roleName?)Sets driver role (loads constructor, calls lifecycle hooks)
setAiMode(mode?, ignoreParams?)Sets AI mode with automatic parameters
setAiParameters(params?)Sets aggression, speed limit, awareness

Respawn & Pooling

MethodDescription
updateActiveRadius(tickTime)Shrinks active radius over time; affected by occlusion
tryRespawn()Tests if vehicle is out of range and ready to respawn
modifyRespawnValues(addActive?, addInner?)Temporarily increases respawn resistance
onRespawn()Post-respawn setup: random paint, increment counter
onRefresh()Full refresh: reset state, reapply role, check headlights
fade(rate, isFadeOut)Gradually shows/hides vehicle mesh

Tracking & Detection

MethodDescription
trackDriving(dt)Tracks road alignment, speed compliance, wrong-way, and signal violations
checkCollisions()Detects and creates collision tables for contacting vehicles
trackCollision(otherId, dt)Updates collision state (active → resolved/abandoned → cleared)
checkOffenses()Tests for police offenses: speeding, racing, reckless, wrongWay, intersection, hitPolice, hitTraffic
triggerOffense(data)Records an offense and fires onPursuitOffense hook

Utilities

MethodDescription
getInteractiveDistance(pos, squared?)Distance from look-ahead point to position
getBrakingDistance(speed?, accel?)Estimated braking distance
checkRayCast(startPos?, endPos?)Static raycast visibility check
honkHorn(duration?)Horn with auto-off
useSiren(duration?, disable?)Lightbar siren with auto-off
checkTimeOfDay()Returns true if daytime

Internals

Damage Limits

LevelThresholdPurpose
Minor50Triggers tracking
Stop1,000Standard role pulls over
Major30,000Vehicle disabled

Respawn System

Vehicles maintain an activeRadius that shrinks over time. When focusDist > finalRadius:

  1. Check all non-traffic vehicles aren't within innerRadius
  2. Turn off headlights, enter fadeOut state
  3. Fade mesh to invisible → enter queued state
  4. Traffic system repositions vehicle ahead of player

Driving Score Tracking

  • speedScore: Decreases when driving 20%+ over speed limit
  • directionScore: Decreases when wrong-way driving
  • driveScore: Decreases when rapidly switching sides of road
  • signalFault: Set when running a red light or stop sign

Offense Detection

Offenses require policeVars.strictness > 0 and are scored:

OffenseScoreCondition
speeding100≥120% speed limit AND ≥60 km/h
racing200≥200% speed limit AND ≥100 km/h
reckless250driveScore below strictness threshold
wrongWay150directionScore below threshold
intersection200Red light or stop sign violation
hitPolice200Collision with police vehicle
hitTraffic100Collision during pursuit or hit-and-run

Usage Example

-- Access a traffic vehicle
local veh = gameplay_traffic.getTrafficData()[vehId]
log("I", "", veh.modelName .. " at " .. tostring(veh.speed) .. " m/s")
log("I", "", "Role: " .. veh.roleName)
log("I", "", "Pursuit mode: " .. veh.pursuit.mode)

-- Modify respawn behavior
veh:modifyRespawnValues(500) -- keep active longer
veh.enableRespawn = false    -- prevent respawning entirely

See Also

  • gameplay/traffic/baseRole - Traffic Role Base Class - Related reference
  • gameplay/traffic/trafficUtils - Traffic Utility Functions - Related reference
  • Gameplay Systems Guide - Guide

Traffic Utilities

Reference for `gameplay_traffic_trafficUtils`, a collection of utility functions used by the traffic system for spawn point finding, vehicle group creation, road validation, and role loading.

Empty Traffic Role

Reference for the `empty` traffic role, a minimal role that prevents extra actions or AI logic from being applied to a vehicle. Used when a vehicle needs to be in the traffic system but should not hav

On this page

ConstructorKey PropertiesKey MethodsState ManagementRole & AIRespawn & PoolingTracking & DetectionUtilitiesInternalsDamage LimitsRespawn SystemDriving Score TrackingOffense DetectionUsage ExampleSee Also