RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
Flowgraph Base ModuleFlowgraph Base NodeFlowgraph Base State NodeFlowgraph Node BuilderFlowgraph GraphFlowgraph Group HelperFlowgraph LinkFlowgraph ManagerNew Node TemplateFlowgraph PinFlowgraph States ManagerFlowgraph UtilsFlowgraph Variable Storage
Route Distance (Flowgraph Node)Closest Road (Flowgraph Node)Custom Lua (Flowgraph Node)Distance Between (Flowgraph Node)Waypoints Distance (Flowgraph Node)File Exists (Flowgraph Node)Get First Element of Table (Flowgraph Node)Get Level Data (Flowgraph Node)Get Map Objects IDs by DynField (Flowgraph Node)Get Table Value By Key (Flowgraph Node)GHOST (Flowgraph Node)Hide Loading Screen (Flowgraph Node)Color HSV (Flowgraph Node)Line Point From Xnorm (Flowgraph Node)Load Level (Flowgraph Node)Load Project (Flowgraph Node)On Menu (Flowgraph Node)Perlin Noise (Flowgraph Node)Pop Action Map (Flowgraph Node)Get Project InfoPush Action MapRandom ColorRandom NumberRandom QuaternionRandom VectorRoad PropertiesGet Navgraph RouteRoute PositionTemplate NodeTimeTimed SequenceTo NumberTo StringWorld Editor Open

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 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

PinTypeDescription
posvec3Position to check against the navgraph

Output Pins

PinTypeDescription
name_astringName of the closer navgraph node
pos_avec3Position of node A
roadId_anumberDecalRoad ID of node A (hidden)
roadIdx_anumberDecalRoad index of node A (hidden)
name_bstringName of the farther navgraph node
pos_bvec3Position of node B
roadId_bnumberDecalRoad ID of node B (hidden)
roadIdx_bnumberDecalRoad index of node B (hidden)
distnumberDistance from position to road segment
existsboolTrue if a road was found (hidden)
widthnumberRoad width at closest point (hidden)
projectedPointvec3Position projected onto the road segment (hidden)

Internals

Key Methods

MethodDescription
work()Finds closest road, calculates projections, populates outputs
findDecalroad(name)Parses navgraph node name to extract DecalRoad ID and index

How It Works

  1. Only recalculates when pos changes (caches oldPos).
  2. Calls map.findClosestRoad(pos) to get the two endpoint node names and distance.
  3. Calculates xnorm (projection parameter) on the line segment; swaps A/B so A is always the closer endpoint.
  4. Projects pos onto the segment using setLerp for the projected point.
  5. Interpolates road width from both node radii: lerp(a.radius, b.radius, xnorm) * 2.
  6. 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) * 2

Key Dependencies

  • map.findClosestRoad() - finds nearest navgraph road segment
  • map.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

Route Distance (Flowgraph Node)

- **Node Name:** `Route Distance`

Custom Lua (Flowgraph Node)

- **Node Name:** `Custom Lua`

On this page

OverviewPin SchemaInput PinsOutput PinsInternalsKey MethodsHow It WorksUsage ExampleKey DependenciesSee Also