Class Vector2
A 2-dimensional vector, set of coordinates or dimensions
Constructor
new Vector2(x, y)
Parameters
- x
- Type:
number
- Type:
- y
- Type:
number | undefined
- Type:
Examples
ts
new Vector2(2, 4)
// Result: Vector2(2, 4)
new Vector2(3)
// Result: Vector2(3, 3)
Properties
x
- Type:
number
y
- Type:
number
ZERO
Returns a vector with each value set to zero
Static
Type:
Vector2
Example
tsVector2.ZERO // Result: Vector2(0, 0)
clone
Returns a clone of this vector
- Type:
Vector2
Methods
round()
Round the values of this vector to whole numbers
Details
Returns:
this
Example
tsnew Vector2(3.6, 1.3).round() // Result: Vector2(4, 1)
getDistance(x, y)
Get the distance between this vector and another
Details
- Parameters
- x
- Type:
number
- Type:
- y
- Type:
number
- Type:
- x
- Returns
- Type:
number
- Type:
getDistance(vector2)
Get the distance between this vector and another
Details
- Parameters
- vector2
- Type:
Vector2
- Type:
- vector2
- Returns
- Type:
number
- Type:
add(vector2A, vector2B)
Add two vectors together
Details
- Static
- Parameters
- vector2A
- Type:
Vector2
- Type:
- vector2B
- Type:
Vector2
- Type:
- vector2A
- Returns
- Type:
Vector2
- Type:
subtract(vector2A, vector2B)
Subtract two vectors
Details
- Static
- Parameters
- vector2A
- Type:
Vector2
- Type:
- vector2B
- Type:
Vector2
- Type:
- vector2A
- Returns
- Type:
Vector2
- Type:
scale(vector2, scalar)
Scale a vector
Details
- Static
- Parameters
- vector2
- Type:
Vector2
- Type:
- scalar
- Type:
number
- Type:
- vector2
- Returns
- Type:
Vector2
- Type:
magnitude(vector2)
Get the magnitude of a vector
Details
- Static
- Parameters
- vector2
- Type:
Vector2
- Type:
- vector2
- Returns
- Type:
number
- Type:
normalize(vector2)
Normalize a vector
Details
- Static
- Parameters
- vector2
- Type:
Vector2
- Type:
- vector2
- Returns
- Type:
Vector2
- Type:
sqrDistance (vector2A, vector2B)
Get the square distance between two vectors
Details
- Static
- Parameters
- vector2A
- Type:
Vector2
- Type:
- vector2B
- Type:
Vector2
- Type:
- vector2A
- Returns
- Type:
number
- Type:
lerp(vector2A, vector2B, t)
Lerp between two vectors
Details
- Static
- Parameters
- vector2A
- Type:
Vector2
- Type:
- vector2B
- Type:
Vector2
- Type:
- t
- Type:
number
- Type:
- vector2A
- Returns
- Type:
Vector2
- Type: