MiscClient

getClosestPointOnLine

GET_CLOSEST_POINT_ON_LINE0x21C235BC64831E5A

The GTA V native GET_CLOSEST_POINT_ON_LINE of the MISC namespace, as LS:MP client scripts call it: the global function getClosestPointOnLine, in JavaScript and in Lua.

SignatureJavaScript
getClosestPointOnLine(
  x1: number,
  y1: number,
  z1: number,
  x2: number,
  y2: number,
  z2: number,
  x3: number,
  y3: number,
  z3: number,
  clamp: boolean
): { x: number, y: number, z: number }
SignatureLua
getClosestPointOnLine(
  x1: number,
  y1: number,
  z1: number,
  x2: number,
  y2: number,
  z2: number,
  x3: number,
  y3: number,
  z3: number,
  clamp: boolean
): Vector3

Usage

JavaScript
const { x, y, z } = getClosestPointOnLine(x1, y1, z1, x2, y2, z2, x3, y3, z3, clamp);
Lua
local coords = getClosestPointOnLine(x1, y1, z1, x2, y2, z2, x3, y3, z3, clamp)
-- coords.x, coords.y, coords.z

Three consecutive numbers can be given as one vector: { x, y, z } (or [x, y, z]) in JavaScript, a Vector3 in Lua.

JavaScript · with vectors
const coords = getClosestPointOnLine(pos1, pos2, pos3, clamp);
Lua · with vectors
local coords = getClosestPointOnLine(pos1, pos2, pos3, clamp)

Parameters

ParameterTypeJavaScriptLuaDescription
x1floatnumbernumber
y1floatnumbernumber
z1floatnumbernumber
x2floatnumbernumber
y2floatnumbernumber
z2floatnumbernumber
x3floatnumbernumber
y3floatnumbernumber
z3floatnumbernumber
clampBOOLbooleanbooleansets whether the product should be clamped between the given coordinates

Returns

Vector3 JavaScript { x: number, y: number, z: number }, Lua Vector3

A 3D vector. JavaScript gets a plain { x, y, z } object; Lua gets a real Vector3, with .x .y .z and arithmetic. As an argument, one vector fills three consecutive coordinates.

Reference

Namespace
Misc MISC
In the game
Vector3 GET_CLOSEST_POINT_ON_LINE(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, BOOL clamp)
Hash
0x21C235BC64831E5A

Open in the interactive natives reference