Skip to content

Vector

Note

Note that this class represents both Float Vectors and Short Vectors.

Fields

int: x

vector.x

int: y

vector.y

int: z

vector.z

Functions

boolean: vector:iszero

vector:iszero()

Returns whether or not the vector is (0, 0, 0)

vector:scale

vector:scale(float: factor)
vector:scale(short: factor)

Scales up the vector by the factor.

vector:normalize

vector:normalize()
vector:normalize(Vector: dstVec)

Returns or writes the normalized vector.

vector:magnitude

vector:magnitude()

Returns the magnitude of the vector.

vector:cross

vector:cross(Vector: vec1, Vector: vec2)

Writes the cross product of 2 vectors.

vector:set

vector:set(float: X, float: Y, float: Z)
vector:set(short: X, short: Y, short: Z)

Sets the fields of a vector.

vector:get

vector:get()

Returns the fields of the vector

Example:

local function command_func(caller, args)
    local position = caller:getposition()

    local x, y, z = position:get()

    return string.format("Your position: %s %s %s", x, y, z)
end

vector:toshort

vector:toshort()

Transforms a float vector into a short vector.

vector:tofloat

vector:tofloat()

Transforms a short vector into a float vector.

vector:min

vector:min(Vector: vec1, Vector: vec2)

Writes a new vector with the smallest values from the 2 source vectors.

vector:max

vector:max(Vector: vec1, Vector: vec2)

Writes a new vector with the biggest values from the 2 source vectors.