API ReferenceGE Extensionsflowgraphnodesvehicle
Distance From Ground
- **Node Name:** `Distance From Ground`
Overview
- Node Name:
Distance From Ground - Category:
repeat_instant - File:
extensions/flowgraph/nodes/vehicle/groundDistance.lua
Reports the distance of the lowest point of a vehicle's bounding box from the terrain below. Uses raycasts from each of the 8 OBB corners to find the minimum clearance.
Pin Schema
Input Pins
| Pin | Type | Default | Description |
|---|---|---|---|
vehId | number | - | ID of the vehicle to measure |
zOffset | number | 10 | (hidden, hardcoded) Height offset for raycast origin. Increase if getting infinite values when close to terrain |
Output Pins
| Pin | Type | Description |
|---|---|---|
lowestDistance | number | Distance of the lowest bounding box point from the terrain below |
Internals
Key Methods
| Method | Description |
|---|---|
init() | Initializes drawDebug data flag (default false) |
work() | Iterates over all 8 OBB corners, raycasts downward from each, finds the minimum distance |
Debug Drawing
When self.data.drawDebug is true, the node draws text labels at each OBB point showing the distance to the ground.
How It Works
- Gets the vehicle's spawn world-oriented bounding box (OBB) via
veh:getSpawnWorldOOBB(). - For each of the 8 corner points:
- Creates an offset point raised by
zOffsetunits on the Z axis. - Calls
be:getSurfaceHeightBelow(offset)to get the terrain height directly below. - Computes
point.z - hitas the distance from that corner to the ground. - Tracks the minimum distance across all 8 points.
- Creates an offset point raised by
- Outputs the lowest distance. A value of
math.hugemeans no terrain was found below.
Usage Example
-- In a flowgraph:
-- [Distance From Ground] ← vehId ← [Vehicle ID]
-- → lowestDistance → [Compare < 0.1] → [Vehicle is grounded]
-- Programmatic equivalent:
local veh = scenetree.findObjectById(vehId)
local oobb = veh:getSpawnWorldOOBB()
local lowest = math.huge
for i = 0, 7 do
local point = oobb:getPoint(i)
local offset = vec3(point)
offset.z = offset.z + 10
local hit = be:getSurfaceHeightBelow(offset)
if hit then
lowest = math.min(lowest, point.z - hit)
end
endKey Dependencies
veh:getSpawnWorldOOBB()- returns the vehicle's oriented bounding box in world spacebe:getSurfaceHeightBelow()- raycasts downward to find terrain surface height
See Also
- Align for Coupling (Flowgraph Node) - Related reference
- Apply Velocity to Vehicle (Flowgraph Node) - Related reference
- Boost Vehicle (Flowgraph Node) - Related reference
- FlowGraph Guide - Guide