RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
Bus DriverDamage GoalDemolition DerbyDistance GoalDrift GoalFinish Race GoalNo-Move GoalPosition GoalQuick RaceQuick Race LoaderRace MarkersRace DebugRace Goals ManagerRace UIScenario HelperScenario EngineScenarios LoaderSpeed GoalTime Limit GoalWaypoint ActionScenario Waypoints

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 Extensionsscenario

Scenario Waypoints

M.dependencies = {'scenario_scenarios'}

Dependencies

M.dependencies = {'scenario_scenarios'}

The core waypoint tracking system for scenario races. Manages waypoint progression, branching paths, lap counting, vehicle trigger detection via wheel-corner intersection, and marker mode updates.


Public API (Exports)

FunctionSignatureDescription
M.initialise()Sets up waypoints, builds successor graph, initializes vehicles
M.getVehicleWaypointData(vehicleId)Returns deep copy of vehicle's waypoint progress
M.onScenarioChange(scenario)Clears state when scenario is nil
M.onScenarioRestarted(scenario)Re-initializes branching and successor graph
M.onScenarioVehicleTrigger(vid, wpData, dtOff)Processes vehicle waypoint triggers, updates race progress and UI
M.onVehicleAIStateChanged(data)Initializes waypoint tracking for newly AI-controlled vehicles
M.onPreRender(dtReal, dtSim, dtRaw)Per-frame: checks wheel-corner intersections with waypoints
M.activateWaypointBranch(branchName, vehicleId, dtOff)Inserts branch waypoints into vehicle's config
M.deactivateWaypointBranch(branchName)Removes branch waypoints (currently disabled)
M.updateResetVehicleData(vehicleId, curWpIndex, nextWpIndex)Resets vehicle to specific waypoint indices
M.isFinalWaypoint(vehicleId, waypointName)Checks if waypoint is the final one
M.onSerialize()-
M.onDeserialized(data)-
M.onClientEndMission()-

State Structure

M.state = {
  vehicleWaypointsData = {},   -- vid → {cur, next, lap, waypointConfig, nextWps, wheelOffsets, ...}
  nextWpForVehicle = {},       -- vid → next waypoint index
  waypointBranches = {},       -- branchName → list of waypoint names
  branchGraph = {},            -- branchName → {index → {cpName, successors, isFinalWaypoint, ...}}
  pathnodes = {},              -- wpName → pathnode object (for intersection tests)
}

How It Works

Initialization

  1. Builds a successor graph from BranchLapConfig and lapConfigBranches
  2. Each node in the graph stores its successors, branch info, and whether it's a final waypoint
  3. Creates pathnode objects for each waypoint (used for intersection detection)
  4. Calls race_marker.setupMarkers() with all waypoint positions
  5. Initializes per-vehicle tracking data with wheel offsets for corner-based detection

Waypoint Detection (onPreRender)

  1. Each frame, updates vehicle wheel corner positions using rotation and offset
  2. For each vehicle, checks if any wheel corner line segment (previous→current) intersects a target waypoint's pathnode
  3. Intersection uses the pathnode's intersectCorners method with time interpolation
  4. On hit, triggers onScenarioVehicleTrigger which advances waypoint progress

Waypoint Progression

  1. processWaypoint(vid) advances cur/next indices
  2. Determines marker modes: default, next, branch, lap, final
  3. Handles branching: when a waypoint has multiple successors, shows branch mode (yellow)
  4. Handles laps: detects lap completion, fires onRaceLap hook
  5. When final waypoint reached on final lap, calls scenario_scenarios.endRace()

Branching

  1. BranchLapConfig can contain arrays (branch choices) instead of strings
  2. activateWaypointBranch inserts a branch's waypoints into the vehicle's config at the current position
  3. Successor graph pre-computes all possible paths through branches

Marker Mode Assignment

ModeWhen
defaultNormal next checkpoint
nextCheckpoint after the next one (preview)
branchNext checkpoint has multiple successors
lapFinal checkpoint of a non-final lap
finalFinal checkpoint of the final lap
startRolling start checkpoint

| M.addWaypointBranch | varies | Assigned as addWaypointBranch | | M.onUpdate | varies | Assigned as onUpdate |

Usage Example

-- Waypoints are initialized automatically by scenarios.lua during pre-running state
-- Get current progress for a vehicle:
local wpData = scenario_waypoints.getVehicleWaypointData(vehicleId)
if wpData then
  print("Current waypoint:", wpData.cur, "Lap:", wpData.lap)
end

-- Reset a vehicle to a specific waypoint:
scenario_waypoints.updateResetVehicleData(vehicleId, 3, 4)

Key Notes

  • Uses wheel corner positions (not vehicle center) for precise checkpoint detection
  • Time interpolation (tNorm) provides sub-frame accuracy for timing
  • Branching is stored per-vehicle - different vehicles can take different branches
  • disableWaypointTimes is auto-set when branches exist (comparisons become invalid)
  • Rolling start uses a special initial state with cur = -2, next = -1
  • The successor graph handles circular paths (last WP → first WP) for lap races
  • Serialization converts vehicle ID keys to name keys for save/load

Additional Exports

  • M.onDrawDebug - (undocumented)

See Also

  • Scenario Bus Driver - Bus Route Scenario Logic - Related reference
  • Scenario Damage Goal - Damage-Based Win/Fail Condition - Related reference
  • Scenario Demolition Derby - Last Vehicle Moving Wins - Related reference
  • Scenario System Guide - Guide

Waypoint Action

A scenario goal that displays flash messages when the player reaches specific waypoints. Unlike other goals, this is purely informational - it doesn't trigger win or fail conditions.

Attention Marker

A race checkpoint marker that displays a single floating arrow ribbon. Designed for walking/on-foot scenarios with a bobbing animation and height offset when the player is nearby.

On this page

DependenciesPublic API (Exports)State StructureHow It WorksInitializationWaypoint Detection (onPreRender)Waypoint ProgressionBranchingMarker Mode Assignment| M.addWaypointBranch | varies | Assigned as addWaypointBranch | | M.onUpdate | varies | Assigned as onUpdate |Usage ExampleKey NotesAdditional ExportsSee Also