Class: Vector2
Vector 2D
Constructors
Properties
Methods
- getAngle
- slerp
- lerp
- set
- distance
- add
- sub
- scale
- multiply
- multiplyScaler
- divide
- neg
- abs
- length
- getAngle
- unt
- angleTo
- equals
- pal
- clone
- copyFrom
- dot
- normalize
- addInPlace
- addScalar
- clampScalar
Constructors
constructor
• new Vector2(x?, y?): Vector2
Create a new Vector2.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
x | number | 0 | The x component of the vector, which defaults to 0. |
y | number | 0 | The y component of the vector, which defaults to 0. |
Returns
Defined in
Properties
ZERO
▪ Static Readonly ZERO: Vector2
Defined in
SAFE_MAX
▪ Static Readonly SAFE_MAX: Vector2
Defined in
SAFE_MIN
▪ Static Readonly SAFE_MIN: Vector2
Defined in
x
• x: number = 0.0
The x component of the vector, the default value is 0.
Defined in
y
• y: number = 0.0
The y component of the vector, the default value is 0.
Defined in
Methods
getAngle
▸ getAngle(a, b): number
Returns the Angle, in radians, between two vectors.
Parameters
| Name | Type | Description |
|---|---|---|
a | Vector2 | Vector a |
b | Vector2 | Vector b |
Returns
number
result
Defined in
slerp
▸ slerp(from, to, t): Vector2
Computes linear interpolation between two vectors.
Parameters
| Name | Type | Description |
|---|---|---|
from | Vector2 | starting vector |
to | Vector2 | The vector in which you interpolate |
t | number |
Returns
Defined in
lerp
▸ lerp(from, to, t): Vector2
Linear interpolation between two vectors.
Parameters
| Name | Type | Description |
|---|---|---|
from | Vector2 | starting vector |
to | Vector2 | The vector in which you interpolate |
t | number |
Returns
Defined in
set
▸ set(x?, y?): this
Sets the x and y components of this vector.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
x | number | 0 | The x component of the vector, which defaults to 0. |
y | number | 0 | The y component of the vector, which defaults to 0. |
Returns
this
Defined in
distance
▸ distance(a): number
Calculate the distance between this vector and the incoming vector.
Parameters
| Name | Type | Description |
|---|---|---|
a | Vector2 | Target vector |
Returns
number
Defined in
add
▸ add(a, target?): Vector2
Add the vectors.
Parameters
| Name | Type |
|---|---|
a | Vector2 |
target? | Vector2 |
Returns
Defined in
sub
▸ sub(a, target?): Vector2
Vector subtraction
Parameters
| Name | Type |
|---|---|
a | Vector2 |
target? | Vector2 |
Returns
Defined in
scale
▸ scale(v): this
Let's multiply the x and y values of this vector times v.
Parameters
| Name | Type |
|---|---|
v | number |
Returns
this
Defined in
multiply
▸ multiply(a, target?): Vector2
Let's multiply the x and y values of this vector by a.
Parameters
| Name | Type |
|---|---|
a | number |
target? | Vector2 |
Returns
Defined in
multiplyScaler
▸ multiplyScaler(a): this
Let's multiply the x and y values of this vector by a.
Parameters
| Name | Type |
|---|---|
a | number |
Returns
this
Defined in
divide
▸ divide(v, target?): Vector2
We're going to divide the x and y values of this vector by v.
Parameters
| Name | Type |
|---|---|
v | number |
target? | Vector2 |
Returns
Defined in
neg
▸ neg(target?): Vector2
Vector inversion
Parameters
| Name | Type |
|---|---|
target? | Vector2 |
Returns
Defined in
abs
▸ abs(): number
Returns
number
Defined in
length
▸ length(): number
Length of vector
Returns
number
Defined in
getAngle
▸ getAngle(target): number
Returns the Angle, in radians, between the current vector and the target vector.
Parameters
| Name | Type | Description |
|---|---|---|
target | Vector2 | Target vector |
Returns
number
Defined in
unt
▸ unt(target?): Vector2
Parameters
| Name | Type |
|---|---|
target? | Vector2 |
Returns
Defined in
angleTo
▸ angleTo(v): number
Parameters
| Name | Type |
|---|---|
v | Vector2 |
Returns
number
Defined in
equals
▸ equals(a): boolean
Whether two vectors are equal
Parameters
| Name | Type | Description |
|---|---|---|
a | Vector2 | Vector of comparison |
Returns
boolean
Defined in
pal
▸ pal(a): number
Parameters
| Name | Type |
|---|---|
a | Vector2 |
Returns
number
Defined in
clone
▸ clone(): Vector2
Returns a new vector that has the same x and y as the current vector.
Returns
Defined in
copyFrom
▸ copyFrom(v): Vector2
Copy the x and y properties of the source vector to this vector
Parameters
| Name | Type | Description |
|---|---|---|
v | Vector2 | Source vector |
Returns
Defined in
dot
▸ dot(value): number
Take the dot product of two vectors.
Parameters
| Name | Type | Description |
|---|---|---|
value | Vector2 | Target vector |
Returns
number
Defined in
normalize
▸ normalize(): this
Convert this vector to a unit vector.
Returns
this
Defined in
addInPlace
▸ addInPlace(otherVector): this
Add two vectors
Parameters
| Name | Type | Description |
|---|---|---|
otherVector | Vector2 | Additive vector |
Returns
this
Defined in
addScalar
▸ addScalar(s): this
Add the scalar to the x and y of this vector.
Parameters
| Name | Type | Description |
|---|---|---|
s | number | Additive scalar |
Returns
this
Defined in
clampScalar
▸ clampScalar(minVal, maxVal): Vector2
Parameters
| Name | Type | Description |
|---|---|---|
minVal | number | Component will be limited to the minimum value of |
maxVal | number | The component will be limited to the maximum value of |

