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
| Method | Signature | Returns | Description |
|---|---|---|---|
init | (path, name, forceId) | nil | Initializes with defaults |
getFrom / getTo | () | pathnode | Returns the from/to pathnode objects |
setFrom / setTo | (id) | nil | Sets from/to pathnode ID and rechecks mode |
setMode | (mode) | nil | Sets containment mode: 'waypoint', 'capsules', or 'navpath' |
contains | (point, state) | hit, t | Tests if a position is within the segment |
finished | (point, state) | hit, t | Tests if the vehicle reached the end pathnode |
isValid | () | bool | Returns false if from/to nodes are missing or equal |
getBeNavpath | () | bool | True if both endpoints use navgraph mode |
addCapsule | (pos, radius, name, index) | nil | Adds a capsule point |
removeCapsule | (index) | nil | Removes a capsule point |
getCapsuleCount | () | number | Total capsule points (including from/to) |
getCapsuleNode | (i) | node | Returns capsule node at index |
capsuleContains | (point, id) | bool | Tests if point is within a capsule pair |
fillNavpath | () | nil | Fills capsule points from navgraph path |
onSerialize / onDeserialized | Serialization support | ||
drawDebug | (drawMode) | nil | Debug visualization |
Internals
| Field | Type | Description |
|---|---|---|
path | Path | Parent path reference |
id | number | Unique ID |
from / to | number | Pathnode IDs for endpoints |
mode | string | 'waypoint', 'capsules', or 'navpath' |
capsulePoints | table | Intermediate capsule points between from/to |
Containment Modes
| Mode | Behavior |
|---|---|
waypoint | Always "inside" if already in this segment; otherwise checks if vehicle enters from node |
capsules | Tests point against a chain of capsule volumes between from and to |
navpath | Like capsules but auto-filled from navgraph path between from/to nodes |
How It Works
- Waypoint mode: The simplest mode - a vehicle is inside a segment if it was already in that segment, or if it enters the
frompathnode (viaintersectCorners) - Capsule/navpath mode: A chain of capsule volumes (cylinder-like) connects from → intermediate points → to. Each capsule pair is tested via
xnormDistanceToLineSegmentwith interpolated radii finished()always checks thetopathnode viaintersectCornersregardless of modefillNavpath()usesmap.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
| Function | Signature | Returns | Description |
|---|---|---|---|
M.checkMode | () | nil | checkMode |
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.