Skip to content

tes3vector4⚓︎

A set of 4 floating-point numbers.

Properties⚓︎

w⚓︎

The 1st value in the vector.

Returns:

  • result (number)

x⚓︎

The 2nd value in the vector.

Returns:

  • result (number)

y⚓︎

The 3rd value in the vector.

Returns:

  • result (number)

z⚓︎

The 4th value in the vector.

Returns:

  • result (number)

Methods⚓︎

__tostring⚓︎

Converts the vector to a string with 2 decimal places.

local result = myObject:__tostring()

Returns:

  • result (string)

copy⚓︎

Creates a copy of the vector.

local result = myObject:copy()

Returns:


distance⚓︎

Calculates the distance to another vector in the standard way, i.e., using the Euclidean distance.

local result = myObject:distance(vec)

Parameters:

Returns:

  • result (number)

distanceChebyshev⚓︎

Calculates the distance to another vector, using the Chebyshev metric, which is defined as

math.max(math.abs(v1.x - v2.x), math.abs(v1.y - v2.y), math.abs(v1.z - v2.z), math.abs(v1.w - v2.w))

This is useful for ensuring that the x, y, z, and w coordinates between two vectors are all (independently) within a certain distance from each other.

Here is a geometric description of the difference between the normal distance and the Chebyshev distance for two tes3vector3s v1 and v2:

  • If v1:distance(v2) <= 1, then v2 is contained in a sphere around v1 with radius 1 (i.e. diameter 2).
  • If v1:distanceChebyshev(v2) <= 1, then v2 is contained within a cube centered around v1, where the cube has length 2.
local result = myObject:distanceChebyshev(vec)

Parameters:

Returns:

  • result (number)

distanceManhattan⚓︎

Calculates the distance to another vector, using the Manhattan (i.e. city block) metric. In the two-dimensional case, the Manhattan metric can be thought of as the distance that two taxis will have to travel if they're following a grid system. The formula for the Manhattan distance is

math.abs(v1.x - v2.x) + math.abs(v1.y - v2.y) + math.abs(v1.z - v2.z) + math.abs(v1.w - v2.w)

This is useful for checking how far you'd actually have to move if you're only allowed to move along one axis at a time.

local result = myObject:distanceManhattan(vec)

Parameters:

Returns:

  • result (number)

length⚓︎

Calculates the length of the vector.

local result = myObject:length()

Returns:

  • result (number)

Functions⚓︎

new⚓︎

Creates a new vector. If no parameters are provided, an empty set will be constructed.

local vector = tes3vector4.new(x, y, z, w)

Parameters:

  • x (number): Default: 0.
  • y (number): Default: 0.
  • z (number): Default: 0.
  • w (number): Default: 0.

Returns:


Math Operations⚓︎

Addition (+)⚓︎

Left operand type Right operand type Result type Description
tes3vector4 tes3vector4 tes3vector4 Standard vector addition.

Division (/)⚓︎

Left operand type Right operand type Result type Description
tes3vector4 number tes3vector4 Divides the vector by a scalar.

Length (#)⚓︎

Result type Description
number Evaluates to the vector's length in game units.

Multiplication (*)⚓︎

Left operand type Right operand type Result type Description
tes3vector4 tes3vector4 tes3vector4 The per-element multiplication of two vectors.
tes3vector4 number tes3vector4 Multiplies the vector by a scalar.

Subtraction (-)⚓︎

Left operand type Right operand type Result type Description
tes3vector4 tes3vector4 tes3vector4 Standard vector subtraction.