ScriptsAboutBlogToolsKnowledge BaseReviewsFAQBasketDocsSupport
shared

GetDistanceBetweenCoords

FiveM shared native documentation with a Lua example.

Summary

Returns the distance between two 3D points. Useful, though #(vec1 - vec2) is cheaper for simple distance checks in loops.

Returns

float — the distance.

Parameters

x1,y1,z1floatFirst point.
x2,y2,z2floatSecond point.
useZbooleanWhether to include the Z axis.

Example

local d = GetDistanceBetweenCoords(x1,y1,z1, x2,y2,z2, true)

-- cheaper alternative in tight loops:
local d2 = #(vector3(x1,y1,z1) - vector3(x2,y2,z2))

Common pitfalls

  • For per-frame checks, prefer #(a - b) — it's faster.
  • Set useZ true when height matters (e.g. multi-floor buildings).

Related natives

Related guides

Need protected areas on your map?

Viper Safe-Zone draws polygon safe zones in-game — no hand-edited coordinates — with weapon, combat and vehicle-speed rules per zone.

See Viper Safe-Zone →