API ReferenceGE Extensionsflowgraphnodesutil
Closest Road (Flowgraph Node)
- **Node Name:** `Closest Road`
Overview
- Node Name:
Closest Road - Category:
repeat_instant - File:
extensions/flowgraph/nodes/util/closestRoad.lua
Finds the closest road segment on the navgraph from a given position. Returns both endpoint nodes, distance, projected point, road width, and optional DecalRoad IDs.
Pin Schema
Input Pins
| Pin | Type | Description |
|---|---|---|
pos | vec3 | Position to check against the navgraph |
Output Pins
| Pin | Type | Description |
|---|---|---|
name_a | string | Name of the closer navgraph node |
pos_a | vec3 | Position of node A |
roadId_a | number | DecalRoad ID of node A (hidden) |
roadIdx_a | number | DecalRoad index of node A (hidden) |
name_b | string | Name of the farther navgraph node |
pos_b | vec3 | Position of node B |
roadId_b | number | DecalRoad ID of node B (hidden) |
roadIdx_b | number | DecalRoad index of node B (hidden) |
dist | number | Distance from position to road segment |
exists | bool | True if a road was found (hidden) |
width | number | Road width at closest point (hidden) |
projectedPoint | vec3 | Position projected onto the road segment (hidden) |
Internals
Key Methods
| Method | Description |
|---|---|
work() | Finds closest road, calculates projections, populates outputs |
findDecalroad(name) | Parses navgraph node name to extract DecalRoad ID and index |
How It Works
- Only recalculates when
poschanges (cachesoldPos). - Calls
map.findClosestRoad(pos)to get the two endpoint node names and distance. - Calculates
xnorm(projection parameter) on the line segment; swaps A/B so A is always the closer endpoint. - Projects
posonto the segment usingsetLerpfor the projected point. - Interpolates road width from both node radii:
lerp(a.radius, b.radius, xnorm) * 2. - Attempts to parse DecalRoad IDs from navgraph node names (format:
DecalRoadNNN_MMM).
Usage Example
-- Find closest road from a position:
local name_a, name_b, distance = map.findClosestRoad(pos)
local nodeA = map.getMap().nodes[name_a]
local nodeB = map.getMap().nodes[name_b]
-- Project position onto road:
local xnorm = clamp(pos:xnormOnLine(nodeA.pos, nodeB.pos), 0, 1)
local projected = vec3()
projected:setLerp(nodeA.pos, nodeB.pos, xnorm)
-- Get road width at that point:
local width = lerp(nodeA.radius, nodeB.radius, xnorm) * 2Key Dependencies
map.findClosestRoad()- finds nearest navgraph road segmentmap.getMap().nodes- access to navgraph node positions and radii
See Also
- Route Distance (Flowgraph Node) - Related reference
- Custom Lua (Flowgraph Node) - Related reference
- Distance Between (Flowgraph Node) - Related reference
- FlowGraph Guide - Guide