| Property | Value |
|---|---|
| Native Name | VDIST |
| Hash | 0x2A488C176D52CCA5 |
| Return Type | float |
| Parameters | x1 (float), y1 (float), z1 (float), x2 (float), y2 (float), z2 (float) |
Description: Calculates the distance between two points in 3D space. For performance reasons, consider using direct mathematical calculations for distance, as they can be more efficient than calling this native function.
NativeDB Introduced: v323
Parameters
x1(float) — X coordinate of the first point.y1(float) — Y coordinate of the first point.z1(float) — Z coordinate of the first point. Represents the height or elevation at the first point.x2(float) — X coordinate of the second point.y2(float) — Y coordinate of the second point.z2(float) — Z coordinate of the second point. Represents the height or elevation at the second point.
Examples
-- Define a set of coordinates
local coords = vector3(145.0, 200.0, 1000.0)
-- Get the player's current ped
local playerPed = PlayerPedId()
-- Get the player's current coordinates
local coordsPlayer = GetEntityCoords(playerPed, false)
-- Calculate the distance between the player and the coordinates
local distance = Vdist(coordsPlayer.x, coordsPlayer.y, coordsPlayer.z, coords.x, coords.y, coords.z)
if (distance < 10.0) then
print("You are close to the coordinates")
else
print("You are far from the coordinates")
end
// Define a set of coordinates
const coords = [145.0, 200.0, 1000.0];
// Get the player's current ped
const playerPed = PlayerPedId();
// Get the player's current coordinates
const coordsPlayer = GetEntityCoords(playerPed, false);
// Calculate the distance between the player and the coordinates
const distance = Vdist(coordsPlayer[0], coordsPlayer[1], coordsPlayer[2], coords[0], coords[1], coords[2]);
if (distance < 10.0) {
console.log("You are close to the coordinates");
} else {
console.log("You are far from the coordinates");
}
using static CitizenFX.Core.Native.API;
// Define a set of coordinates
Vector3 coords = new Vector3(145.0f, 200.0f, 1000.0f);
// Get the player's current ped
Ped playerPed = PlayerPedId();
// Get the player's current coordinates
Vector3 coordsPlayer = GetEntityCoords(playerPed, false);
// Calculate the distance between the player and the coordinates
float distance = Vdist(coordsPlayer.X, coordsPlayer.Y, coordsPlayer.Z, coords.X, coords.Y, coords.Z);
if (distance < 10.0f)
{
Debug.WriteLine("You are close to the coordinates");
}
else
{
Debug.WriteLine("You are far from the coordinates");
}