ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. getDistanceBetweenPoints3D

Function

getDistanceBetweenPoints3D

Server and clientMiscellaneousIdentical to MTA:SA

Computes the distance between two points in space.

Syntax

float getDistanceBetweenPoints3D(float x1, float y1, float z1, float x2, float y2, float z2)

Arguments

x1float
X of the first point.
y1float
Y of the first point.
z1float
Z of the first point.
x2float
X of the second point.
y2float
Y of the second point.
z2float
Z of the second point.

Returns

Distance in metres.

Example

local function near(a, b, range)
    local x1, y1, z1 = getElementPosition(a)
    local x2, y2, z2 = getElementPosition(b)
    return getDistanceBetweenPoints3D(x1, y1, z1, x2, y2, z2) <= range
end

See also