SixL server API / common / Vector3

Interface: Vector3

A 3D vector: a position in metres, a direction or a rotation in degrees.

Operations return new vectors; the vector they are called on is never changed.

Remarks

Reached as mp.Vector3 (the constructor); entity positions are returned as instances of it. SixL differences from RAGE MP: toAngles returns a vector; max and min also take a vector.

Example

const a = new mp.Vector3(1, 2, 3);
    const b = a.add(new mp.Vector3(0, 0, 10)); // (1, 2, 13)

Extends

Properties

x

x: number

East-west coordinate, metres.

Inherited from

IVector3.x


y

y: number

North-south coordinate, metres.

Inherited from

IVector3.y


z

z: number

Height, metres.

Inherited from

IVector3.z

Methods

add()

add(otherVec): Vector3

Adds a vector component by component, or a number to every component.

Parameters

otherVec

number | Vector3

The vector to add (metres), or a number.

Returns

Vector3

A new vector, this + otherVec.

Example

new mp.Vector3(1, 2, 3).add(new mp.Vector3(1, 1, 1)); // (2, 3, 4)
    new mp.Vector3(1, 2, 3).add(1); // (2, 3, 4)

angleTo()

angleTo(otherVec): number

The angle between this vector and another.

Parameters

otherVec

Vector3

The other vector.

Returns

number

The angle in radians, 0..π; 0 when either vector is zero.

Example

new mp.Vector3(1, 0, 0).angleTo(new mp.Vector3(0, 1, 0)); // 1.5707963 (π / 2)

clone()

clone(): Vector3

A copy of the vector.

Returns

Vector3

A new vector with the same components.

Example

const copy = pos.clone();

cross()

cross(otherVec): Vector3

The cross product: a vector perpendicular to both.

Parameters

otherVec

Vector3

The other vector.

Returns

Vector3

A new vector, this x otherVec.

Example

new mp.Vector3(1, 0, 0).cross(new mp.Vector3(0, 1, 0)); // (0, 0, 1)

distance()

distance(otherVec): number

The distance to another point.

Parameters

otherVec

Vector3

The other point (metres).

Returns

number

The 3D distance in metres.

Remarks

A SixL addition; RAGE MP has no distance on vectors (use entity.dist(position)).

Example

new mp.Vector3(0, 0, 0).distance(new mp.Vector3(0, 3, 4)); // 5

divide()

divide(divisor): Vector3

Divides by a number, or component by component by another vector.

Parameters

divisor

number | Vector3

A number, or a vector.

Returns

Vector3

A new vector.

Example

new mp.Vector3(2, 4, 6).divide(2); // (1, 2, 3)

dot()

dot(otherVec): number

The dot product.

Parameters

otherVec

Vector3

The other vector.

Returns

number

x1*x2 + y1*y2 + z1*z2.

Example

new mp.Vector3(1, 0, 0).dot(new mp.Vector3(0, 1, 0)); // 0

equals()

equals(otherVec): boolean

Exact component-wise equality.

Parameters

otherVec

Vector3

The vector to compare to.

Returns

boolean

True when x, y and z are all equal (no tolerance).

Example

new mp.Vector3(1, 2, 3).equals(new mp.Vector3(1, 2, 3)); // true

length()

length(): number

The length (magnitude) of the vector.

Returns

number

The length, in the vector's unit (metres for positions).

Example

new mp.Vector3(3, 4, 0).length(); // 5

max()

max(otherVec?): number | Vector3

The component-wise maximum with a vector, or the largest component.

Parameters

otherVec?

Vector3

Optional. Another vector.

Returns

number | Vector3

With a vector: a new vector of the larger components. Without: the largest of x, y, z.

Example

new mp.Vector3(1, 5, 3).max(); // 5

min()

min(otherVec?): number | Vector3

The component-wise minimum with a vector, or the smallest component.

Parameters

otherVec?

Vector3

Optional. Another vector.

Returns

number | Vector3

With a vector: a new vector of the smaller components. Without: the smallest of x, y, z.

Example

new mp.Vector3(1, 5, 3).min(); // 1

multiply()

multiply(otherVec): Vector3

Multiplies every component by a number, or component by component by a vector.

Parameters

otherVec

number | Vector3

The factor: a number, or a vector.

Returns

Vector3

A new vector.

Example

new mp.Vector3(1, 2, 3).multiply(2); // (2, 4, 6)
    new mp.Vector3(1, 2, 3).multiply(new mp.Vector3(2, 0, 1)); // (2, 0, 3)

negative()

negative(): Vector3

The opposite vector (every sign flipped).

Returns

Vector3

A new vector, -this.

Example

new mp.Vector3(1, -2, 0).negative(); // (-1, 2, -0)

normalize()

normalize(): Vector3

A copy with length 1 and the same direction.

Returns

Vector3

The unit vector; the zero vector for a zero vector.

Remarks

A SixL addition, the same as unit().

Example

new mp.Vector3(0, 10, 0).normalize(); // (0, 1, 0)

subtract()

subtract(otherVec): Vector3

Subtracts a vector component by component, or a number from every component.

Parameters

otherVec

number | Vector3

The vector to subtract (metres), or a number.

Returns

Vector3

A new vector, this - otherVec.

Example

new mp.Vector3(5, 5, 5).subtract(new mp.Vector3(1, 2, 3)); // (4, 3, 2)
    new mp.Vector3(5, 5, 5).subtract(5); // (0, 0, 0)

toAngles()

toAngles(): Vector3

The GTA rotation that points along this vector.

Returns

Vector3

A vector of rotation in degrees: x = pitch, y = roll (always 0), z = yaw (heading; +90 faces -x).

Remarks

RAGE MP's typings declare an array of two; SixL returns a Vector3.

Example

new mp.Vector3(0, 1, 0).toAngles(); // (0, 0, 0): north

toArray()

toArray(): Array3d

The components as an array.

Returns

Array3d

[x, y, z].

Example

new mp.Vector3(1, 2, 3).toArray(); // [1, 2, 3]

unit()

unit(): Vector3

A copy with length 1 and the same direction.

Returns

Vector3

The unit vector; the zero vector for a zero vector.

Example

new mp.Vector3(0, 10, 0).unit(); // (0, 1, 0)