Vector3::length

From RAGE Multiplayer Wiki
Jump to navigation Jump to search

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