Vector3::length

From RAGE Multiplayer Wiki
Revision as of 05:58, 31 May 2019 by Micaww (talk | contribs) (Created page with "This function returns the magnitude of a Vector3. It's calculated by square rooting the result of '''x * x + y * y + z * z'''. ==Syntax== <pre> vector.length(); </pre> ==...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This function returns the magnitude of a Vector3.

It's calculated by square rooting the result of x * x + y * y + z * z.

Syntax

vector.length();

Returns

  • number The vector's magnitude.

Example

This example calculates the distance between two players.

Server-Side
const vec1 = mp.players.at(0).position;
const vec2 = mp.players.at(1).position;

const distance = vec1.subtract(vec2).length();

// distance is the distance between the two players

See Also