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
Race PacenoteRace PathRace PathnodeRaceRace SegmentRace Start Position

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 Extensionsgameplayrace

Race Segment

Object class representing a segment (connection) between two pathnodes in a race path. Supports three containment modes: waypoint, capsules, and navpath.

Object class representing a segment (connection) between two pathnodes in a race path. Supports three containment modes: waypoint, capsules, and navpath.


Constructor

local Segment = require('/lua/ge/extensions/gameplay/race/segment')
local seg = Segment(path, name, forceId)

Public API

MethodSignatureReturnsDescription
init(path, name, forceId)nilInitializes with defaults
getFrom / getTo()pathnodeReturns the from/to pathnode objects
setFrom / setTo(id)nilSets from/to pathnode ID and rechecks mode
setMode(mode)nilSets containment mode: 'waypoint', 'capsules', or 'navpath'
contains(point, state)hit, tTests if a position is within the segment
finished(point, state)hit, tTests if the vehicle reached the end pathnode
isValid()boolReturns false if from/to nodes are missing or equal
getBeNavpath()boolTrue if both endpoints use navgraph mode
addCapsule(pos, radius, name, index)nilAdds a capsule point
removeCapsule(index)nilRemoves a capsule point
getCapsuleCount()numberTotal capsule points (including from/to)
getCapsuleNode(i)nodeReturns capsule node at index
capsuleContains(point, id)boolTests if point is within a capsule pair
fillNavpath()nilFills capsule points from navgraph path
onSerialize / onDeserializedSerialization support
drawDebug(drawMode)nilDebug visualization

Internals

FieldTypeDescription
pathPathParent path reference
idnumberUnique ID
from / tonumberPathnode IDs for endpoints
modestring'waypoint', 'capsules', or 'navpath'
capsulePointstableIntermediate capsule points between from/to

Containment Modes

ModeBehavior
waypointAlways "inside" if already in this segment; otherwise checks if vehicle enters from node
capsulesTests point against a chain of capsule volumes between from and to
navpathLike capsules but auto-filled from navgraph path between from/to nodes

How It Works

  1. Waypoint mode: The simplest mode - a vehicle is inside a segment if it was already in that segment, or if it enters the from pathnode (via intersectCorners)
  2. Capsule/navpath mode: A chain of capsule volumes (cylinder-like) connects from → intermediate points → to. Each capsule pair is tested via xnormDistanceToLineSegment with interpolated radii
  3. finished() always checks the to pathnode via intersectCorners regardless of mode
  4. fillNavpath() uses map.getPath() to find navgraph waypoints between from/to and creates capsule points from them

Usage Examples

-- Create a segment between two pathnodes
local seg = Segment(path, "Start to Turn 1")
seg:setFrom(pn1.id)
seg:setTo(pn2.id)

-- Check if vehicle reached the end
local hit, t = seg:finished(vehiclePos, vehicleState)
if hit then
  -- advance to successor segments
end

-- Use navpath mode for better tracking along roads
seg:setMode('navpath')

Notes

  • Capsule volumes use linearly interpolated radii between adjacent points
  • Navpath mode falls back to waypoint if either endpoint isn't a navgraph node
  • isValid() rejects segments where from/to are missing or identical
FunctionSignatureReturnsDescription
M.checkMode()nilcheckMode

See Also

  • Race Pacenote - Related reference
  • Race Path - Related reference
  • Race Pathnode - Related reference
  • Gameplay Systems Guide - Guide

Race

Core race management class that tracks vehicle progress through a race path, handles lap counting, segment transitions, checkpoint timing, AI vehicles, recovery, off-track detection, and integration w

Race Start Position

Object class representing a spawn/recovery position in a race path. Stores position and rotation, and provides methods to calculate vehicle placement transforms and teleport vehicles.

On this page

ConstructorPublic APIInternalsContainment ModesHow It WorksUsage ExamplesNotesSee Also