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
| Function | Signature | Description |
|---|---|---|
onUpdate | () | Calculate remaining distance, check wrong way |
setRacePath | (data) | Load path with options (reverse, maxWrongWayDist) |
getPathData | () → table | Raw path object |
getWaypoints | () → table | Sorted waypoint positions |
getRemainingDist | () → number | Meters remaining to finish |
getGoingWrongWay | () → bool | Currently driving against path direction |
getWrongWayFail | () → bool | Exceeded max wrong-way distance |
getDistToIntendedRoad | () → number | Distance to nearest path segment |
getDisableWrongWayAndDist | () → bool | Whether wrong-way/dist checks are disabled |
getDriftDebugInfo | () → table | Debug toggle state |
getGC | () → number | Profiler 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 → failWrong-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 standstillWrong-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_pathand can be reversed withdata.reverse = true - If reversed, both the path and extracted waypoints are inverted
distToIntendedRoadis 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
maxWrongWayDistis 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