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
Drift Zone BoundsDrift Race PathDrift UI DisplayDrift Detection EngineDrift SystemDrift Quick MessagesDrift Save/LoadDrift ScoreboardDrift Scoring SystemDrift AudioDrift StallingDrift StatisticsDrift Stunt Zones

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 Extensionsgameplaydrift

Drift Race Path

Reference for `gameplay_drift_destination`, which tracks remaining distance along a race path and detects wrong-way driving.

Reference for gameplay_drift_destination, which tracks remaining distance along a race path and detects wrong-way driving.


Overview

Loads a race path file, calculates the vehicle's closest point on the path, measures remaining distance to the end, and detects when the player is driving the wrong way. Used by drift challenges and freeroam drift spots that have a defined start-to-finish direction.


Exports

FunctionSignatureDescription
onUpdate()Calculate remaining distance, check wrong way
setRacePath(data)Load path with options (reverse, maxWrongWayDist)
getPathData() → tableRaw path object
getWaypoints() → tableSorted waypoint positions
getRemainingDist() → numberMeters remaining to finish
getGoingWrongWay() → boolCurrently driving against path direction
getWrongWayFail() → boolExceeded max wrong-way distance
getDistToIntendedRoad() → numberDistance to nearest path segment
getDisableWrongWayAndDist() → boolWhether wrong-way/dist checks are disabled
getDriftDebugInfo() → tableDebug toggle state
getGC() → numberProfiler garbage
reset()Reset distance counters
M.getDisableWrongWayAndDist()-
M.getDistToIntendedRoad()-
M.getDriftDebugInfo()-
M.getGC()-
M.getGoingWrongWay()-
M.getPathData()-
M.getRemainingDist()-
M.getWaypoints()-
M.getWrongWayFail()-
M.onUpdate()-
M.reset()-
M.setRacePath(data)-

How It Works

-- Set up a race path for a drift spot
gameplay_drift_destination.setRacePath({
  filePath = "/levels/.../race.race.json",
  reverse = false,              -- flip path direction
  maxWrongWayDist = 10,         -- meters before wrongWayFail
  disableWrongWayAndDist = false -- skip all checks
})

-- Each frame:
-- 1. Find closest line segment on path to vehicle
-- 2. Sum remaining segment distances from that point
-- 3. Check if velocity dot product with path direction is negative → wrong way
-- 4. Accumulate wrong-way distance; if > maxWrongWayDist → fail

Wrong-Way Detection

local desiredDirection = nextWaypointPos - previousWaypointPos
goingWrongWay = vel > 0.5 and desiredDirection:dot(vehVelocity) <= 0
-- Only triggers above velocity threshold to avoid false positives at standstill

Wrong-Way Failure

Accumulates actual distance driven while going wrong way. Once currWrongWayDist > maxWrongWayDist, wrongWayFail becomes true (consumed by driftSpots to trigger improper end).


Key Behaviors

  • Path is loaded via gameplay_race_path and can be reversed with data.reverse = true
  • If reversed, both the path and extracted waypoints are inverted
  • distToIntendedRoad is the perpendicular distance to the nearest path segment (used for out-of-bounds checks)
  • Fires extensions.hook("onDriftWrongWay") each frame while going wrong way
  • Default maxWrongWayDist is 10 meters

See Also

  • drift/bounds - Drift Zone Boundary Detection - Related reference
  • drift/display - Drift UI & HUD Management - Related reference
  • drift/drift - Core Drift Detection Engine - Related reference
  • Gameplay Systems Guide - Guide

Drift Zone Bounds

Reference for `gameplay_drift_bounds`, which detects whether the drift vehicle is inside defined zone boundaries and optionally draws them.

Drift UI Display

Reference for `gameplay_drift_display`, which manages all drift-related UI updates: score display, angle readout, combo timer, flash messages, wrong-way/out-of-bounds warnings, and drift zone completi

On this page

OverviewExportsHow It WorksWrong-Way DetectionWrong-Way FailureKey BehaviorsSee Also