API ReferenceGE Extensionsui
Camera Distance App
Debug app that displays the distance between the camera and the player vehicle.
Debug app that displays the distance between the camera and the player vehicle.
Overview
ui_cameraDistanceApp is a simple debug extension that calculates and displays the distance between the camera and the player vehicle each frame.
Extension path: lua/ge/extensions/ui/cameraDistanceApp.lua
Exports (M)
| Function | Signature | Description |
|---|---|---|
onUpdate | (dtReal, dtSim, dtRaw) | Per-frame hook: computes distance and sends to UI. |
Internals
Per-Frame Logic
local function onUpdate(dtReal, dtSim, dtRaw)
local veh = getPlayerVehicle(0)
if not veh then
guihooks.trigger('cameraDistance', -1, "no vehicle")
return
end
local vehPos = veh:getPosition()
local camPos = core_camera.getPosition()
-- Debug sphere at vehicle position
debugDrawer:drawSphere(vehPos, 0.5, sphereColor)
debugDrawer:drawTextAdvanced(vehPos, "camera distance target", textColor, true, false, textBackgroundColor)
local distance = vehPos:distance(camPos)
guihooks.trigger('cameraDistance', distance)
endUI Communication
Sends distance via guihooks.trigger('cameraDistance', distance). When no vehicle exists, sends -1 with "no vehicle" message.
Debug Visualization
Draws a red sphere (radius 0.5) and text label at the vehicle position in 3D world space using debugDrawer.
How It Works
- Each frame, gets player vehicle position and camera position
- Calculates Euclidean distance between them
- Triggers
cameraDistanceguihook with the value - Draws a debug sphere at the vehicle for visual reference
Additional Exports
The following exports are available but not yet documented in detail:
M.onUpdate