SixL client 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); the positions of streamed entities are instances of it. On the client, the vector takes a number in add, subtract, multiply and divide (applied to every axis), has unit() but no normalize() or distance(), and angleTo returns radians.
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
y
y: number
North-south coordinate, metres.
Inherited from
z
z: number
Height, metres.
Inherited from
Methods
add()
add(otherVec):Vector3
Adds a vector, or a number to every component.
Parameters
otherVec
number | Vector3
The vector to add (metres), or a number added to x, y and z.
Returns
Vector3
A new vector, this + otherVec.
Example
new mp.Vector3(1, 2, 3).add(new mp.Vector3(1, 1, 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 to pi; 0 when either vector is zero.
Example
new mp.Vector3(1, 0, 0).angleTo(new mp.Vector3(0, 1, 0)); // 1.5707963 (pi / 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)
divide()
divide(otherVec):Vector3
Divides by a vector (component by component), or every component by a number.
Parameters
otherVec
number | Vector3
A vector, or the divisor for every component. A zero divides to Infinity or NaN.
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(): number
The largest of x, y and z.
Returns
number
The largest component, a number (not a vector).
Example
new mp.Vector3(1, 5, 3).max(); // 5
min()
min(): number
The smallest of x, y and z.
Returns
number
The smallest component, a number (not a vector).
Example
new mp.Vector3(1, 5, 3).min(); // 1
multiply()
multiply(otherVec):Vector3
Multiplies by a vector (component by component), or every component by a number.
Parameters
otherVec
number | Vector3
A vector, or the factor for every component.
Returns
Vector3
A new vector.
Example
new mp.Vector3(1, 2, 3).multiply(2); // (2, 4, 6)
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)
subtract()
subtract(otherVec):Vector3
Subtracts a vector, or a number from every component.
Parameters
otherVec
number | Vector3
The vector to subtract (metres), or a number subtracted from x, y and z.
Returns
Vector3
A new vector, this - otherVec.
Example
new mp.Vector3(5, 5, 5).subtract(new mp.Vector3(1, 2, 3)); // (4, 3, 2)
toAngles()
toAngles(): Vector3
The rotation that points along this vector.
Returns
Vector3
A vector of rotation in degrees: x is the pitch (up is positive), y is always 0, and z is the heading, 0 for +y, 90 for -x, 180 for -y, 270 for +x, in the range 0 to 360.
Remarks
Partial: the values follow the formulas of the runtime; they have not been checked against RAGE MP's results. Returns a Vector3 here; the RAGE MP typings declare an array of two.
Example
new mp.Vector3(1, 0, 0).toAngles(); // (0, 0, 270)
toArray()
toArray(): Array3d
The components as an array.
Returns
[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 (0, 0, 0) when this vector is zero.
Example
new mp.Vector3(0, 10, 0).unit(); // (0, 1, 0)