RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
Bus DriverDamage GoalDemolition DerbyDistance GoalDrift GoalFinish Race GoalNo-Move GoalPosition GoalQuick RaceQuick Race LoaderRace MarkersRace DebugRace Goals ManagerRace UIScenario HelperScenario EngineScenarios LoaderSpeed GoalTime Limit GoalWaypoint ActionScenario Waypoints

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 Extensionsscenario

Distance Goal

A scenario goal that monitors the distance between two vehicles and triggers win or fail when distance thresholds are exceeded.

A scenario goal that monitors the distance between two vehicles and triggers win or fail when distance thresholds are exceeded.


Internal State

FieldTypeDescription
M.instancesvariesAssigned as {}

Public API

FunctionSignatureDescription
M.init(scenario)Parses and validates distance goals from scenario JSON
M.processState(scenario, state, stateData)Checks distances each tick; triggers result
M.updateFinalStatus(scenario, instance)Reports final goal status to statistics system

Goal JSON Schema

{
  "goal": {
    "distance": {
      "target": "ai_vehicle_1",
      "maxDistance": 50,
      "minDistance": 5,
      "distanceEnable": 30,
      "purpose": "fail",
      "msg": "scenarios.myScenario.tooFar"
    }
  }
}
FieldTypeDefaultDescription
targetstringrequiredName of the target vehicle to measure distance to
maxDistancenumberoptionalFail/win if distance exceeds this value
minDistancenumberoptionalFail/win if distance drops below this value
distanceEnablenumberoptionalOnly start checking after getting within this distance
purposestring"fail""fail" or "win" - what happens when triggered
msglocalizedStringautoCustom message on trigger

How It Works

  1. init filters goals for id == "distance", validates numeric types
  2. Each onRaceTick, calculates distance between the goal vehicle and target
  3. If distanceEnable is set, waits until player is within that range before checking
  4. Once enabled, checks maxDistance and minDistance thresholds
  5. If exceeded, calls showMsg which finishes the scenario as win or fail
  6. Also supports scenario.targetName for scene-object distance checks (legacy)

Usage Examples

-- In scenario JSON: fail if player gets more than 50m from escort target
{
  "vehicles": {
    "scenario_player0": {
      "goal": {
        "distance": {
          "target": "escort_vehicle",
          "maxDistance": 50,
          "purpose": "fail",
          "msg": "scenarios.escort.tooFar"
        }
      }
    }
  }
}

-- Chase scenario: enable distance check only after getting close
{
  "distance": {
    "target": "chase_target",
    "distanceEnable": 30,
    "maxDistance": 100,
    "purpose": "fail"
  }
}

Key Notes

  • Uses helper.getVehicleByName to find the target vehicle object
  • distanceEnable creates a "proximity activation" - goal inactive until close enough
  • Both maxDistance and minDistance can be used together for a distance band
  • Falls back to helper.getDistanceBetweenSceneObjects for legacy scene object tracking

See Also

  • Scenario Bus Driver - Bus Route Scenario Logic - Related reference
  • Scenario Damage Goal - Damage-Based Win/Fail Condition - Related reference
  • Scenario Demolition Derby - Last Vehicle Moving Wins - Related reference
  • Scenario System Guide - Guide

Demolition Derby

A simple demolition derby scenario mode where the last vehicle still moving wins. Tracks all scenario vehicles and declares a winner when only one remains in motion.

Drift Goal

A scenario goal that calculates drift scores from vehicle angle and speed, supports combo chains, and triggers win/fail based on minimum drift score thresholds.

On this page

Internal StatePublic APIGoal JSON SchemaHow It WorksUsage ExamplesKey NotesSee Also