📏 Vector2D
A Vector2D composed of components (X, Y) with floating point precision. Used mainly for HUD and Drawing on screen.
🎒 Examples
local new_vector = Vector2D(1452.5, 512)
🛠 Constructors
Default Constructor
No description provided
local my_vector2d = Vector2D(X?, Y?)
🧽 Properties
🦠 Functions
info
This structure supports +, -, *, /, == and tostring operations.
| Returns | Name | Description | |
|---|---|---|---|
| number | Distance | Distance between two points | |
| number | DistanceSquared | Squared distance between two points | |
| boolean | IsNear | Efficiently checks whether vector is near to another vector within a specified radius | |
| number | Size | Get the length (magnitude) of this vector | |
| number | SizeSquared | Get the squared length of this vector | |
| number | Dot | Dot product of two vectors | |
| number | Cross | Cross product of two vectors | |
| Vector2D | Lerp | Linearly interpolates between this vector and another vector |
Distance
Returns the distance of 2 vectors
local ret = my_vector2d:Distance(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | The vector to get the distance to |
Returns
| Type | Description |
|---|---|
| number | The distance between the vectors |
DistanceSquared
Return the squared distance of 2 vectors
local ret = my_vector2d:DistanceSquared(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | The vector to get the squared distance to |
Returns
| Type | Description |
|---|---|
| number | The squared distance between the vectors |
IsNear
Efficiently checks whether vector is near to another vector within a specified radius
local ret = my_vector2d:IsNear(other, radius)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | The vector to compare to |
| number | radius | Required parameter | The radius to check |
Returns
| Type | Description |
|---|---|
| boolean | If the vector is near to the other vector |
Size
Get the length (magnitude) of this vector
local ret = my_vector2d:Size()
Returns
| Type | Description |
|---|---|
| number | The length of the vector |
SizeSquared
Get the squared length of this vector
local ret = my_vector2d:SizeSquared()
Returns
| Type | Description |
|---|---|
| number | The squared length of the vector |
Dot
Returns the dot product between this vector and another vector
local ret = my_vector2d:Dot(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | The vector to dot with |
Returns
| Type | Description |
|---|---|
| number | the dot product |
Cross
Returns the cross product between this vector and another vector, which for 2D vectors is a scalar value
local ret = my_vector2d:Cross(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | The vector to cross with |
Returns
| Type | Description |
|---|---|
| number | the cross product |
Lerp
Returns the linear interpolation between this vector and another vector by the given alpha
local ret = my_vector2d:Lerp(other, alpha)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | The vector to interpolate to |
| number | alpha | Required parameter | The interpolation alpha, where 0 returns this vector and 1 returns the other vector |
Returns
| Type | Description |
|---|---|
| Vector2D | the interpolated vector |