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.
You can use several operators like + and - to modify and transform Vector3 objects, described below.
You can add two vectors together using the + operator. For example:
newVector = vector1 + vector2
This is equivalent to the add() function.
You can subtract one vector from another using the - operator. For example:
newVector = vector1 - vector2
This is equivalent to the subtract() function.
You can negate a vector using the - operator as a prefix to any vector variable. For example:
negativeVector = -vector1
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.
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.
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"]
Constructors and accessors
Related sample code
Other related reference items
Related help topics
x : numberThe extent of the vector along the X axis.
|
y : numberThe extent of the vector along the Y axis.
|
z : numberThe extent of the vector along the Z axis.
|
add ( vector_a, vector_b ) : stingray.Vector3Adds the two specified vectors together, and returns the resulting vector.
|
vector_a : | The first vector to add. | |
vector_b : | The second vector to add. |
The sum of the two input vectors. |
backward ( ) : stingray.Vector3Returns the backward (negative Y) axis.
|
This function does not accept any parameters. |
The backward vector. |
base ( index ) : stingray.Vector3Returns the base vector with the specified index.
|
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. |
The base vector with the specified index. |
cross ( vector_a, vector_b ) : stingray.Vector3Returns the cross product of the two specified vectors.
|
vector_a : | The first vector. | |
vector_b : | The second vector. |
The cross product. |
Related sample code
distance ( vector_a, vector_b ) : numberReturns the distance between two specified points.
|
vector_a : | The first point. | |
vector_b : | The second point. |
number |
The scalar distance between vector_a and vector_b. |
distance_squared ( vector_a, vector_b ) : numberReturns the square of the distance between two specified points.
|
vector_a : | The first point. | |
vector_b : | The second point. |
number |
The square of the distance between vector_a and vector_b. |
divide ( vector, factor ) : stingray.Vector3Divides the specified vector by a scalar value, and returns the resulting vector.
|
vector : | The vector to divide. | |
factor : | number | A scalar value to divide into the vector. |
The quotient of the input vector and the scalar value. |
divide_elements ( vector_a, vector_b ) : stingray.Vector3Divides each element of vector_a by the corresponding element of vector_b, and returns the resulting vector.
|
vector_a : | The vector to be divided. | |
vector_b : | The vector to divide into vector_a. |
The quotient of the two input vectors. |
dot ( vector_a, vector_b ) : numberReturns the dot product of the two specified vectors.
|
vector_a : | The first vector. | |
vector_b : | The second vector. |
number |
The dot product. |
down ( ) : stingray.Vector3Returns the down (negative Z) axis.
|
element ( vector, index ) : numberReturns the value stored at the specified index within the vector.
|
vector : | 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. |
number |
The value of the element at the specified index. |
equal ( vector_a, vector_b ) : booleanIndicates whether or not the two vectors are identical.
|
vector_a : | The first vector to compare. | |
vector_b : | The second vector to compare. |
boolean |
Returns true if the two vectors are identical, or false otherwise. |
Related sample code
forward ( ) : stingray.Vector3Returns the forward (Y) axis.
|
This function does not accept any parameters. |
The forward vector. |
is_valid ( vector ) : booleanIndicates whether or not the vector is composed entirely of valid values.
|
vector : | The vector to be validated. |
boolean |
Returns true if all components of the vector are valid numbers, or false if any component is #NaN or #INF. |
left ( ) : stingray.Vector3Returns the left (negative X) axis.
|
length ( vector ) : numberReturns the scalar length of the specified vector.
|
vector : | The vector whose length will be returned. |
number |
The length of the vector. |
Related sample code
lerp ( vector_a, vector_b, ratio ) : stingray.Vector3Produces a new vector by interpolating linearly between the two specified vectors with the specified ratio.
|
vector_a : | The first vector. | |
vector_b : | 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. |
The resulting vector. |
make_axes ( vector ) : stingray.Vector3, stingray.Vector3Given the specified vector, returns two orthogonal vectors Y and Z such that the three vectors together form an orthonormal basis, which can be used as an orthogonal coordinate system.
|
vector : | The starting X vector. |
The Y vector orthogonal to vector and to the Z vector. | |
The Z vector orthogonal to vector and to the Y vector. |
max ( vector_a, vector_b ) : stingray.Vector3Returns a vector that contains the largest value for each component from the two specified vectors.
|
vector_a : | The first vector. | |
vector_b : | The second vector. |
The resulting vector. |
min ( vector_a, vector_b ) : stingray.Vector3Returns a vector that contains the smallest value for each component from the two specified vectors.
|
vector_a : | The first vector. | |
vector_b : | The second vector. |
The resulting vector. |
multiply ( vector, factor ) : stingray.Vector3Multiplies the specified vector by a scalar value, and returns the resulting vector.
|
vector : | The vector to multiply. | |
factor : | number | A scalar value to multiply with the vector. |
The product of the input vector and the scalar value. |
multiply_elements ( vector_a, vector_b ) : stingray.Vector3Multiplies each element of vector_a by the corresponding element of vector_b, and returns the resulting vector.
|
vector_a : | The first vector to multiply. | |
vector_b : | The second vector to multiply. |
The product of the two input vectors. |
Related sample code
normalize ( vector ) : stingray.Vector3Normalizes the specified vector -- i.e. converts its scalar length to 1 -- and returns the result.
|
vector : | The vector to be normalized. |
The normalized vector. |
Related sample code
right ( ) : stingray.Vector3Returns the right (X) axis.
|
set_element ( vector, index, value )Sets the specified index within the vector to the specified value.
|
vector : | 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. |
This function does not return any values. |
set_x ( vector, value )Sets the value of the vector's X component.
|
vector : | The vector whose component will be set. | |
value : | number | The new value for the X component. |
This function does not return any values. |
set_xyz ( vector, x, y, z )Sets the values of the vector's X, Y and Z components.
|
vector : | 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. |
This function does not return any values. |
set_y ( vector, value )Sets the value of the vector's Y component.
|
vector : | The vector whose component will be set. | |
value : | number | The new value for the Y component. |
This function does not return any values. |
set_z ( vector, value )Sets the value of the vector's Z component.
|
vector : | The vector whose component will be set. | |
value : | number | The new value for the Z component. |
This function does not return any values. |
subtract ( vector_a, vector_b ) : stingray.Vector3Subtracts vector_b from vector_a, and returns the resulting vector.
|
vector_a : | The starting vector. | |
vector_b : | The vector that will be subtracted. |
The result of the subtraction. |
to_elements ( vector ) : number, number, numberDecomposes the specified vector into its component values.
|
vector : | The vector to be broken down into its components. |
number |
The X component of the vector. |
number |
The Y component of the vector. |
number |
The Z component of the vector. |
to_string ( vector ) : stringReturns a string representation of the specified vector.
|
vector : | The vector to return as a string. |
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.
up ( ) : stingray.Vector3Returns the up (Z) axis.
|
This function does not accept any parameters. |
The up vector. |
Related sample code
x ( vector ) : numberReturns the value of the vector's X component.
|
vector : | The vector whose component will be returned. |
number |
The value of the X component. |
y ( vector ) : numberReturns the value of the vector's Y component.
|
vector : | The vector whose component will be returned. |
number |
The value of the Y component. |
z ( vector ) : numberReturns the value of the vector's Z component.
|
vector : | The vector whose component will be returned. |
number |
The value of the Z component. |
zero ( ) : stingray.Vector3Returns a new vector with all values initialized to zero.
|
This function does not accept any parameters. |
The zero vector. |
Related sample code