Arma 3 Scripting

Command in Math - Geometry

distance

Also available as Markdown and JSON, or read the original wiki page.

Description

Returns a distance in meters between Objects, Positions or Locations.

Important

If positions are supplied as arguments, the coordinates are treated as PositionAGL. If Position2D is supplied, z is assumed 0. If you need distance between two Position3D coordinates, use vectorDistance.

Syntax

Syntax 1

param1 distance param2

Parameters:

Returns: Number - distance in meters or 1e10 if distance cannot be calculated

Syntax 2

location1 distance location2

Parameters:

Returns: Number - distance in meters or 1e10 if distance cannot be calculated

Syntax 3

since arma3 2.18

a distance b

Parameters:

Returns: Number - distance c calculated as c = sqrt(a * a + b * b);

Examples

Example 1

_meters = player distance _object;

Example 2

_meters = player distance [1,2,3];

Example 3

_meters = [1,2,3] distance [4,5,6];

Example 4

_meters = position player distance nearestLocation [position player, "hill"];

See also

distanceSqr · vectorDistance · distance2D

Community notes

Sudden Death

Distance to position3D (array) does not work with Operation Flashpoint, only objects

Armed Assault: position3D (array) and object works

Rommel

This returns the map distance, not the vector distance, [0,0,0] distance [0,0,1] can be >1 or <1, not exactly 1; unlike the vector math.

Igneous01

If a position in format [x, y, z] is provided for both arguments, distance also checks the z dimension as well. Ie: player distance [0,0,200] will return 200, if the player is at this position at ground/sea level.

AgentRev01

When objects are supplied as arguments, distance is calculated from their model center (object modelToWorld [0,0,0]), and not the position returned by getPos/ATL/ASL.

However, this is not relevant for units, as their model center matches their world position.