Ultrasonic

Overview

BeamNG.tech ships with a simulated Ultrasonic sensor which measures distances to nearby surfaces, commonly as an aid to vehicle parking. The range and detection sensitivity are physically-based and customisable by the user. Single or multiple ultrasonic sensors can be attached to vehicles or places at fixed locations.

The sensor is available to use from Python API , via the sensors configuration tools and with the Lua console , for which the commands are noted hereafter.

Usage

Ultrasonic sensors are exposed to Lua through the sensors extension in the tech folder. Using this API, an ultrasonic sensor can be created with various range and detection properties, and either attached to a vehicle or to a fixed point on the map.


sensorId = extensions.tech_sensors.createUltrasonic(vehicleId, args)

Args:

  • vehicleID(int): The vehicle ID. This can be nil (i.e., 0) if the ultrasonic is not to be attached to any vehicle; this also needs isStatic=true.

The args parameter is a Lua table containing as many of the following properties as required. If any property is not set manually then a default value is used, so it is entirely possible to create the ultrasonic sensor with args being an empty table. What follows is a complete list of these arguments:

  • requestedUpdateTime / updateTime(float): How often the ultrasonic sensor should update its readings in the simulator (in seconds). Default: 0.05.

  • updatePriority(float): A scheduling priority value for this ultrasonic sensor, in range 0 to 1. 0 is highest priority, 1 is least. Default: 0.0.

  • pos(Point3F): The position of the ultrasonic sensor in vehicle space (if attached to a vehicle) or in world space (if isStatic=true). Default: Point3F(0.0, -3.0, 1.0).

  • dir(Point3F): The forward direction in which the ultrasonic sensor points (in vehicle space by default, or world space if isDirWorldSpace=true). Default: Point3F(0.0, -1.0, 0.2).

  • up(Point3F): The up direction of the ultrasonic sensor (in vehicle space by default, or world space if isDirWorldSpace=true). Default: Point3F(0.0, 0.0, 1.0).

  • size(table): The horizontal and vertical resolution of the ultrasonic sensor. Default: {200, 200}.

  • fovY(float): The vertical field of view of the ultrasonic sensor, in degrees. Default: 70.0.

  • nearFarPlanes(table): The near and far plane distances of the ultrasonic sensor, in metres. Default: {0.05, 5.1}.

  • rangeRoundness(float): The general roundness of the ultrasonic sensor range shape. Can be negative. Default: -1.15.

  • rangeCutoffSensitivity(float): A cutoff sensitivity parameter for the ultrasonic sensor range-shape. Default: 0.0.

  • rangeShape(float): The shape of the ultrasonic sensor range-shape in the range [0, 1], going from conical to spherical. Default: 0.3.

  • rangeFocus(float): The focus parameter for the ultrasonic sensor range-shape. Default: 0.376.

  • rangeMinCutoff(float): The minimum cut-off distance for the ultrasonic sensor range-shape. Nothing closer than this will be detected. Default: 0.1.

  • rangeDirectMaxCutoff(float): The maximum cut-off distance for the ultrasonic sensor range-shape. This parameter is a hard cutoff - nothing further than this will be detected, although other parameters can also control the maximum distance. Default: 5.0.

  • sensitivity(float): The sensitivity of the ultrasonic sensor detection. Default: 3.0.

  • fixedWindowSize(float): Used with sensitivity to set how sharply the ultrasonic sensor detects surfaces. Default: 10.0.

  • isVisualised(bool): A flag which indicates if the ultrasonic sensor should be visualised. Default: true.

  • isStatic(bool): True if the ultrasonic sensor is fixed to a point on the map, false if it is attached to a vehicle. Default: false.

  • isSnappingDesired(bool): True if the ultrasonic sensor position should be forced onto the surface of the vehicle, at its closest vehicle point. This is useful if finding it hard to have the ultrasonic sensor on the vehicle itself. False, otherwise, eg if the ultrasonic sensor should be suspended at a fixed point relative to the vehicle. Default: true.

  • isForceInsideTriangle(bool): Used with isSnappingDesired. True, if the ultrasonic sensor should be forced to be inside its nearest vehicle triangle. Otherwise false. Default: true.

  • isDirWorldSpace(bool): Flag which indicates if dir and up are provided in world-space coordinates (true), or the default vehicle space (false). Default: false.

Returns: sensorId(int): The unique Id number of this sensor, in order to refer to it later eg when closing it.


distance = extensions.tech_sensors.getUltrasonicReadings(sensorId)

Args:

sensorId(int): The ID number of the ultrasonic sensor.

Returns: reading(table(float)):

– distance: the latest distance measurement, in meters.

– windowMin: (internal parameter) which indicates the minimum size of the data filtering window used in post-processing. This can usually be ignored.

– windowMax: (internal parameter) which indicates the maximum size of the data filtering window used in post-processing. This can usually be ignored.


activeSensors = extensions.tech_sensors.getActiveUltrasonicSensors()

Returns: activeSensors(table(int)): The ID numbers of all currently active ultrasonic sensors in the simulation.


name = extensions.tech_sensors.getUltrasonicSensorName(sensorId)

Args:

sensorId(int): The ID number of the ultrasonic sensor.

Returns: name(string): The name of the ultrasonic sensor.


isVisualised = extensions.tech_sensors.getUltrasonicIsVisualised(sensorId)

Args:

sensorId(int): The ID number of the ultrasonic sensor.

Returns: isVisualised(bool): True if the ultrasonic sensor is being visualised, otherwise false.


extensions.tech_sensors.setUltrasonicIsVisualised(sensorId, isVisualised)

Args:

sensorId(int): The ID number of the ultrasonic sensor.

isVisualised(bool): A flag which indicates if the ultrasonic sensor should be visualised or not.

Returns: nil.


sensorPosition = extensions.tech_sensors.getUltrasonicSensorPosition(sensorId, isWorldSpace)

Args:

sensorId(int): The ID number of the ultrasonic sensor.

isWorldSpace(bool, optional): If true or omitted, returns the current world-space position. If false, returns the configured position (vehicle space for attached sensors, world space for static sensors).

Returns: sensorPosition(Point3F / Point3D): The position of the ultrasonic sensor.


sensorDirection = extensions.tech_sensors.getUltrasonicSensorDirection(sensorId)

Args:

sensorId(int): The ID number of the ultrasonic sensor.

Returns: sensorDirection(Point3F): The forward direction of the ultrasonic sensor, in the coordinate space the sensor was configured in (isDirWorldSpace).


sensorUp = extensions.tech_sensors.getUltrasonicSensorUp(sensorId)

Args:

sensorId(int): The ID number of the ultrasonic sensor.

Returns: sensorUp(Point3F): The up direction of the ultrasonic sensor, in the coordinate space the sensor was configured in (isDirWorldSpace).


radius = extensions.tech_sensors.getUltrasonicSensorRadius(sensorId, distanceFromSensor)

Args:

sensorId(int): The ID number of the ultrasonic sensor.

distanceFromSensor(float): The distance from the ultrasonic sensor, at which the radius should be computed.

Returns: radius(float): The radius of the range shape at the given distance from the ultrasonic sensor.


maxPendingGpuRequests = extensions.tech_sensors.getUltrasonicMaxPendingGpuRequests(sensorId)

Args:

sensorId(int): The ID number of the Ultrasonic sensor.

Returns: maxPendingGpuRequests(int): The maximum number of pending GPU requests for this Ultrasonic sensor.


requestedUpdateTime = extensions.tech_sensors.getUltrasonicRequestedUpdateTime(sensorId)

Args:

sensorId(int): The ID number of the Ultrasonic sensor.

Returns: requestedUpdateTime(float): The current requested update time used by this Ultrasonic sensor.


updatePriority = extensions.tech_sensors.getUltrasonicUpdatePriority(sensorId)

Args:

sensorId(int): The ID number of the Ultrasonic sensor.

Returns: updatePriority(float): The current update priority used by this Ultrasonic sensor.


extensions.tech_sensors.setUltrasonicSensorPosition(sensorId, pos, isWorldSpace)

Args:

sensorId(int): The ID number of the Ultrasonic sensor.

pos(Point3F): The new sensor position (vehicle space for attached sensors, world space for static sensors).

isWorldSpace(bool, optional): Set to true when providing a world-space position for a static sensor. Passing true for a vehicle-attached sensor is rejected with an error.


extensions.tech_sensors.setUltrasonicSensorDirection(sensorId, dir)

Args:

sensorId(int): The ID number of the Ultrasonic sensor.

dir(Point3F): The new sensor forward direction (in the coordinate space the sensor was created with).


extensions.tech_sensors.setUltrasonicSensorUp(sensorId, up)

Args:

sensorId(int): The ID number of the Ultrasonic sensor.

up(Point3F): The new sensor up direction (in the coordinate space the sensor was created with).


extensions.tech_sensors.setUltrasonicMaxPendingGpuRequests(sensorId, maxPendingGpuRequests)

Args:

sensorId(int): The ID number of the Ultrasonic sensor.

maxPendingGpuRequests(int): The new maximum number of pending GPU requests for this Ultrasonic sensor.


extensions.tech_sensors.setUltrasonicRequestedUpdateTime(sensorId, requestedUpdateTime)

Args:

sensorId(int): The ID number of the Ultrasonic sensor.

requestedUpdateTime(float): The new requested update time for this Ultrasonic sensor.


extensions.tech_sensors.setUltrasonicUpdatePriority(sensorId, updatePriority)

Args:

sensorId(int): The ID number of the Ultrasonic sensor.

updatePriority(float): The new update priority for this Ultrasonic sensor.


The following three functions can be used to send ad-hoc polling requests to an Ultrasonic sensor. This is when we just want an occasional reading. We need to first send a request using sendUltrasonicRequest, then wait for it. We can check it is complete using isRequestComplete (see below), then retrieve it using collectUltrasonicRequest.

requestId = extensions.tech_sensors.sendUltrasonicRequest(sensorId)

Args:

sensorId(int): The ID number of the Ultrasonic sensor.

Returns: The unique Id number of the ad-hoc sensor polling request which is being sent.


isComplete = extensions.tech_sensors.isRequestComplete(requestId)

Args:

requestId(int): The ID number of the ad-hoc sensor polling request to check on.

Returns: isComplete(bool): True if the ad-hoc polling request has been completed, otherwise false.


data = extensions.tech_sensors.collectUltrasonicRequest(requestId)

Args:

requestId(int): The ID number of the ad-hoc sensor polling request.

Returns: data(table): The Ultrasonic readings.


extensions.tech_sensors.removeSensor(sensorId)

Args:

sensorId(int): The ID number of the Ultrasonic sensor to remove.

Returns: nil.


Last modified: November 23, 2026

On this page:

Any further questions?

Join our discord
Our documentation is currently incomplete and undergoing active development. If you have any questions or feedback, please visit this forum thread.