API ReferenceGE Extensionsflowgraphnodesvehicleai
AI Follow Waypoints
- **Node Name:** `AI Follow Waypoints`
Overview
- Node Name:
AI Follow Waypoints - Category:
once_f_duration - File:
extensions/flowgraph/nodes/vehicle/ai/followWaypoints.lua
Drives a vehicle along a list of navgraph waypoints using AI path following. Supports multiple laps and optional stopping at the finish. Duration state transitions from inactive → started → finished when all laps are complete.
Pin Schema
Input Pins
| Pin | Type | Default | Description |
|---|---|---|---|
navgraphPath | table (navgraphPath) | - | Array of waypoint names for the AI to follow |
vehId | number | - | Vehicle ID (uses player vehicle if empty) |
lapCount | number | 1 | Number of laps to drive (hidden) |
stopAtFinish | bool | true | If true, AI stops at the last waypoint (hidden) |
Output Pins
| Pin | Type | Description |
|---|---|---|
finalWp | string | Name of the final waypoint in the route (hidden) |
Internals
Key Methods
| Method | Description |
|---|---|
init() | Calls onNodeReset() |
_executionStopped() | Calls onNodeReset() |
onNodeReset() | Clears path, lap counters, and duration state |
getVeh() | Resolves vehicle by ID or player vehicle |
workOnce() | Sends the path to the AI via ai.driveUsingPath() |
work() | Monitors vehicle position to track lap completion |
AI Command
ai.driveUsingPath({
wpTargetList = aiPath,
wpSpeeds = wpSpeeds,
noOfLaps = lapCount,
aggression = 1
})wpSpeeds: IfstopAtFinishis false, sets a high speed (100) for the final waypoint.- For multi-lap routes, the first waypoint is appended to the path to allow the AI to continue seamlessly.
Lap Tracking
- Monitors vehicle proximity to the final waypoint.
- When the vehicle enters the final waypoint's radius, increments
lapsDone. - Uses
lapFlagto prevent double-counting (resets when vehicle is closer to the first waypoint). - When
lapsDone == lapCount, sets duration state tofinished.
How It Works
- On first execution, reads the navgraph path and sends
ai.driveUsingPath(). - Each frame during
startedstate, checks vehicle position against waypoint positions. - Tracks lap completion by detecting entry into the final waypoint radius.
- After all laps complete, transitions to
finishedduration state. - The
finalWpoutput provides the name of the last waypoint for external monitoring.
Usage Example
-- Drive AI along a route:
-- navgraphPath = {"wp_001", "wp_002", "wp_003", "wp_004"}
-- vehId = aiVehicleId
-- lapCount = 1
-- stopAtFinish = true
-- Multi-lap race:
-- navgraphPath = route from Get Navgraph Route node
-- lapCount = 3
-- stopAtFinish = false (keep speed through finish)
-- Chain with route planning:
-- Get Navgraph Route → navgraphRoute → AI Follow Waypoints navgraphPathKey Dependencies
ai.driveUsingPath()- AI waypoint-based path followingmap.getMap().nodes- navgraph node data for position/radius checks
See Also
- AI Parameters (Flowgraph Node) - Related reference
- AI Arrive (Flowgraph Node) - Related reference
- AI Chase (Flowgraph Node) - Related reference
- FlowGraph Guide - Guide