Vector3 - stingray.Vector3 object reference - Stingray Lua API Reference

stingray.Vector3 object reference

Description

Describes a three-dimensional vector.

NOTE: Vector3 objects are temporary. You can only use them in the frame in which they were generated. If you need to save a Vector3 across multiple frames, use a Vector3Box instead. For more information, see Object Lifetimes and Userdata Binding.

Operators

You can use several operators like + and - to modify and transform Vector3 objects, described below.

Addition: +

You can add two vectors together using the + operator. For example:

newVector = vector1 + vector2

This is equivalent to the add() function.

Subtraction: -

You can subtract one vector from another using the - operator. For example:

newVector = vector1 - vector2

This is equivalent to the subtract() function.

Negation: -

You can negate a vector using the - operator as a prefix to any vector variable. For example:

negativeVector = -vector1

Multiplication: *

You can multiply a vector by a scalar value using the * operator. For example:

newVector = vector * scalarFactor

This is equivalent to the multiply() function. See also multiply_elements(), which lets you multiply two vectors together per-element.

Division: /

You can divide a vector by a scalar value using the / operator. For example:

newVector = vector / scalarFactor

This is equivalent to the divide() function. See also divide_elements(), which lets you divide one vector by another per-element.

Accessing components: []

You can set and retrieve component values by using the [] operator. Use the indices 1 or "x" for the X component, 2 or "y" for the Y component, and 3 or "z" for the Z component. For example:

yComponentValue = vector[2]
zComponentValue = vector["z"]

Data Members

x : number

The extent of the vector along the X axis.

y : number

The extent of the vector along the Y axis.

z : number

The extent of the vector along the Z axis.

Functions

Parameters

vector_a :

stingray.Vector3

The first vector to add.

vector_b :

stingray.Vector3

The second vector to add.

Returns

stingray.Vector3

The sum of the two input vectors.

Parameters
This function does not accept any parameters.
Returns

stingray.Vector3

The backward vector.

Parameters

index :

integer

The index of the base vector to return. Use 0 for the X axis, use 1 for the Y axis, and use 2 for the Z axis.

Returns

stingray.Vector3

The base vector with the specified index.

Parameters

vector_a :

stingray.Vector3

The first vector.

vector_b :

stingray.Vector3

The second vector.

Returns

stingray.Vector3

The cross product.

Parameters

vector_a :

stingray.Vector3

The first point.

vector_b :

stingray.Vector3

The second point.

Returns

number

The scalar distance between vector_a and vector_b.

Parameters

vector_a :

stingray.Vector3

The first point.

vector_b :

stingray.Vector3

The second point.

Returns

number

The square of the distance between vector_a and vector_b.

Parameters

vector :

stingray.Vector3

The vector to divide.

factor :

number

A scalar value to divide into the vector.

Returns

stingray.Vector3

The quotient of the input vector and the scalar value.

Parameters

vector_a :

stingray.Vector3

The vector to be divided.

vector_b :

stingray.Vector3

The vector to divide into vector_a.

Returns

stingray.Vector3

The quotient of the two input vectors.

Parameters

vector_a :

stingray.Vector3

The first vector.

vector_b :

stingray.Vector3

The second vector.

Returns

number

The dot product.

Parameters
This function does not accept any parameters.
Returns

stingray.Vector3

The down vector.

Parameters

vector :

stingray.Vector3

The vector whose component will be returned.

index :

integer

The index of the component to return. Use 1 for the X component, 2 for the Y component, or 3 for the Z component.

Returns

number

The value of the element at the specified index.

Parameters

vector_a :

stingray.Vector3

The first vector to compare.

vector_b :

stingray.Vector3

The second vector to compare.

Returns

boolean

Returns true if the two vectors are identical, or false otherwise.

Parameters
This function does not accept any parameters.
Returns

stingray.Vector3

The forward vector.

Parameters

vector :

stingray.Vector3

The vector to be validated.

Returns

boolean

Returns true if all components of the vector are valid numbers, or false if any component is #NaN or #INF.

Parameters
This function does not accept any parameters.
Returns

stingray.Vector3

The left vector.

Parameters

vector :

stingray.Vector3

The vector whose length will be returned.

Returns

number

The length of the vector.

Parameters

vector_a :

stingray.Vector3

The first vector.

vector_b :

stingray.Vector3

The second vector.

ratio :

number

The interpolation ratio, or weight. May be any value between 0 and 1 inclusive. Values closer to 0 produce vectors closer to vector_a; values closer to 1 produce vectors closer to vector_b.

Returns

stingray.Vector3

The resulting vector.

Parameters

vector :

stingray.Vector3

The starting X vector.

Returns

stingray.Vector3

The Y vector orthogonal to vector and to the Z vector.

stingray.Vector3

The Z vector orthogonal to vector and to the Y vector.

Parameters

vector_a :

stingray.Vector3

The first vector.

vector_b :

stingray.Vector3

The second vector.

Returns

stingray.Vector3

The resulting vector.

Parameters

vector_a :

stingray.Vector3

The first vector.

vector_b :

stingray.Vector3

The second vector.

Returns

stingray.Vector3

The resulting vector.

Parameters

vector :

stingray.Vector3

The vector to multiply.

factor :

number

A scalar value to multiply with the vector.

Returns

stingray.Vector3

The product of the input vector and the scalar value.

Parameters

vector_a :

stingray.Vector3

The first vector to multiply.

vector_b :

stingray.Vector3

The second vector to multiply.

Returns

stingray.Vector3

The product of the two input vectors.

Parameters

vector :

stingray.Vector3

The vector to be normalized.

Returns

stingray.Vector3

The normalized vector.

Parameters
This function does not accept any parameters.
Returns

stingray.Vector3

The right vector.

Parameters

vector :

stingray.Vector3

The vector whose component will be set.

index :

integer

The index of the component to set. Use 1 for the X component, 2 for the Y component, or 3 for the Z component.

value :

number

The value to set at the specified index.

Returns
This function does not return any values.
Parameters

vector :

stingray.Vector3

The vector whose component will be set.

value :

number

The new value for the X component.

Returns
This function does not return any values.
Parameters

vector :

stingray.Vector3

The vector whose components will be set.

x :

number

The new value for the X component.

y :

number

The new value for the Y component.

z :

number

The new value for the Z component.

Returns
This function does not return any values.
Parameters

vector :

stingray.Vector3

The vector whose component will be set.

value :

number

The new value for the Y component.

Returns
This function does not return any values.
Parameters

vector :

stingray.Vector3

The vector whose component will be set.

value :

number

The new value for the Z component.

Returns
This function does not return any values.
Parameters

vector_a :

stingray.Vector3

The starting vector.

vector_b :

stingray.Vector3

The vector that will be subtracted.

Returns

stingray.Vector3

The result of the subtraction.

Parameters

vector :

stingray.Vector3

The vector to be broken down into its components.

Returns

number

The X component of the vector.

number

The Y component of the vector.

number

The Z component of the vector.

Parameters

vector :

stingray.Vector3

The vector to return as a string.

Returns

string

The string representation.

Use this function only for debugging purposes; do not attempt to save the string and read it back into a new vector. Use a Vector3Box to save vectors across multiple frames.

Parameters
This function does not accept any parameters.
Returns

stingray.Vector3

The up vector.

Parameters

vector :

stingray.Vector3

The vector whose component will be returned.

Returns

number

The value of the X component.

Parameters

vector :

stingray.Vector3

The vector whose component will be returned.

Returns

number

The value of the Y component.

Parameters

vector :

stingray.Vector3

The vector whose component will be returned.

Returns

number

The value of the Z component.

Parameters
This function does not accept any parameters.
Returns

stingray.Vector3

The zero vector.