Describes a three-dimensional vector.
NOTE: Vector2 objects are temporary. You can only use them in the frame in which they were generated.
If you need to save a Vector2 across multiple frames, use a Vector2Box instead. For more information, see
Object Lifetimes and Userdata Binding.
You can use several operators like + and - to modify and transform Vector2 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, and 2 or "y"
for the Y component. For example:
yComponentValue = vector[2]
xComponentValue = vector["x"]
|
x : number
The extent of the vector along the X axis.
|
|
y : number
The extent of the vector along the Y axis.
|
|
add ( vector_a, vector_b ) : stingray.Vector2
Adds the two specified vectors together, and returns the resulting vector.
|
|
distance ( vector_a, vector_b ) : number
Returns the distance between two specified points.
|
Parameters Returns number |
The scalar distance between vector_a and vector_b.
|
|
Returns the square of the distance between two specified points.
|
Parameters Returns number |
The square of the distance between vector_a and vector_b.
|
|
divide ( vector, factor ) : stingray.Vector2
Divides the specified vector by a scalar value, and returns the resulting vector.
|
Parameters vector : | stingray.Vector2 | The vector to divide. |
factor : | number | A scalar value to divide into the vector. |
Returns
|
Divides each element of vector_a by the corresponding element of vector_b, and returns the resulting vector.
|
|
dot ( vector_a, vector_b ) : number
Returns the dot product of the two specified vectors.
|
|
Returns the value stored at the specified index within the vector.
|
Parameters vector : | stingray.Vector2 | The vector whose component will be returned. |
index : | integer | The index of the component to return. Use 1 for the X component, or 2 for the Y component. |
Returns number |
The value of the element at the specified index.
|
|
equal ( vector_a, vector_b ) : boolean
Indicates whether or not the two vectors are identical.
|
Parameters Returns boolean |
Returns true if the two vectors are identical, or false otherwise.
|
|
Indicates whether or not the vector is composed entirely of valid values.
|
Parameters Returns boolean |
Returns true if all components of the vector are valid numbers, or false if any component is #NaN or #INF.
|
|
Returns the scalar length of the specified vector.
|
Parameters Returns number |
The length of the vector.
|
|
lerp ( vector_a, vector_b, ratio ) : stingray.Vector2
Produces a new vector by interpolating linearly between the two specified vectors with the specified ratio.
|
Parameters vector_a : | stingray.Vector2 | The first vector. |
vector_b : | stingray.Vector2 | 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
|
max ( vector_a, vector_b ) : stingray.Vector2
Returns a vector that contains the greatest value for each component in the two specified vectors.
|
|
min ( vector_a, vector_b ) : stingray.Vector2
Returns a vector that contains the smallest value for each component in the two specified vectors.
|
|
multiply ( vector, factor ) : stingray.Vector2
Multiplies the specified vector by a scalar value, and returns the resulting vector.
|
Parameters vector : | stingray.Vector2 | The vector to multiply. |
factor : | number | A scalar value to multiply with the vector. |
Returns
|
Multiplies each element of vector_a by the corresponding element of vector_b, and returns the resulting vector.
|
|
Normalizes the specified vector -- i.e. converts its scalar length to 1 -- and returns the result.
|
|
Sets the specified index within the vector to the specified value.
|
Parameters vector : | stingray.Vector2 | The vector whose component will be set. |
index : | integer | The index of the component to set. Use 1 for the X component, or 2 for the Y component. |
value : | number | The value to set at the specified index. |
Returns | This function does not return any values. |
|
Sets the value of the vector's X component.
|
Parameters vector : | stingray.Vector2 | The vector whose component will be set. |
value : | number | The new value for the X component. |
Returns | This function does not return any values. |
|
Sets the values of the vector's X and Y components.
|
Parameters vector : | stingray.Vector2 | 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. |
Returns | This function does not return any values. |
|
Sets the value of the vector's Y component.
|
Parameters vector : | stingray.Vector2 | The vector whose component will be set. |
value : | number | The new value for the Y component. |
Returns | This function does not return any values. |
|
subtract ( vector_a, vector_b ) : stingray.Vector2
Subtracts vector_b from vector_a, and returns the resulting vector.
|
|
Decomposes the specified vector into its component values.
|
Parameters Returns number |
The X component of the vector.
|
number |
The Y component of the vector.
|
|
Returns a string representation of the specified vector.
|
Parameters 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 Vector2Box to save vectors across
multiple frames.
|
x ( vector ) : number
Returns the value of the vector's X component.
|
Parameters Returns number |
The value of the X component.
|
|
y ( vector ) : number
Returns the value of the vector's Y component.
|
Parameters Returns number |
The value of the Y component.
|
|
zero ( ) : stingray.Vector2
Returns a new vector with all values initialized to zero.
|
Parameters | This function does not accept any parameters. |
Returns