---
name: Vector2
last_updated: 2026-06-11T17:05:17Z
type: datatype
summary: "Represents a 2D value with direction and magnitude."
---

# Vector2

Represents a 2D value with direction and magnitude.

**Type:** datatype

## Description

The [Vector2](/docs/reference/engine/datatypes/Vector2.md) data type represents a 2D value with direction and
magnitude. Some applications include GUI elements and 2D mouse positions.

#### Math Operations

The following math operations are valid for the [Vector2](/docs/reference/engine/datatypes/Vector2.md) data type:

| Operation | Description |
| --- | --- |
| [Vector2](/docs/reference/engine/datatypes/Vector2.md) `+` [Vector2](/docs/reference/engine/datatypes/Vector2.md) | Produces a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component of the second added to the corresponding component of the first. |
| [Vector2](/docs/reference/engine/datatypes/Vector2.md) `-` [Vector2](/docs/reference/engine/datatypes/Vector2.md) | Produces a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component of the second subtracted from the corresponding component of the first. |
| [Vector2](/docs/reference/engine/datatypes/Vector2.md) `*` [Vector2](/docs/reference/engine/datatypes/Vector2.md) | Produces a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component of the second multiplied by the corresponding component of the first. |
| [Vector2](/docs/reference/engine/datatypes/Vector2.md) `/` [Vector2](/docs/reference/engine/datatypes/Vector2.md) | Produces a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component of the first divided by the corresponding component of the second. |
| [Vector2](/docs/reference/engine/datatypes/Vector2.md) `*` `number` | Produces a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component multiplied by the number. |
| [Vector2](/docs/reference/engine/datatypes/Vector2.md) `/` `number` | Produces a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component divided by the number. |

## Constructors

### Vector2.new

**Signature:** `Vector2.new(x: number, y: number)`

Returns a [Vector2](/docs/reference/engine/datatypes/Vector2.md) from the given x and y components.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `x` | `number` |  |  |
| `y` | `number` |  |  |

## Constants

| Name | Type | Description |
|------|------|-------------|
| `Vector2.zero` | `Vector2` | A [Vector2](/docs/reference/engine/datatypes/Vector2.md) with a magnitude of zero. |
| `Vector2.one` | `Vector2` | A [Vector2](/docs/reference/engine/datatypes/Vector2.md) with a value of 1 on every axis. |
| `Vector2.xAxis` | `Vector2` | A [Vector2](/docs/reference/engine/datatypes/Vector2.md) with a value of 1 on the X axis. |
| `Vector2.yAxis` | `Vector2` | A [Vector2](/docs/reference/engine/datatypes/Vector2.md) with a value of 1 on the Y axis. |

## Properties

### Vector2.X

**Type:** `number`

The x-coordinate of the [Vector2](/docs/reference/engine/datatypes/Vector2.md).

### Vector2.Y

**Type:** `number`

The y-coordinate of the [Vector2](/docs/reference/engine/datatypes/Vector2.md).

### Vector2.Magnitude

**Type:** `number`

The length of the [Vector2](/docs/reference/engine/datatypes/Vector2.md).

### Vector2.Unit

**Type:** `Vector2`

A normalized copy of the [Vector2](/docs/reference/engine/datatypes/Vector2.md).

## Methods

### Vector2:Cross

**Signature:** `Vector2:Cross(other: Vector2): number`

Returns the cross product of the two vectors.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `other` | `Vector2` |  |  |

**Returns:** `number`

### Vector2:Abs

**Signature:** `Vector2:Abs(): Vector2`

Returns a new vector from the absolute values of the original's
components. For example, a vector of `(-2, 4)` returns a vector of
`(2, 4)`.

**Returns:** `Vector2`

### Vector2:Ceil

**Signature:** `Vector2:Ceil(): Vector2`

Returns a new vector from the ceiling of the original's components. For
example, a vector of `(-2.6, 5.1)` returns a vector of `(-2, 6)`.

**Returns:** `Vector2`

### Vector2:Floor

**Signature:** `Vector2:Floor(): Vector2`

Returns a new vector from the floor of the original's components. For
example, a vector of `(-2.6, 5.1)` returns a vector of `(-3, 5)`.

**Returns:** `Vector2`

### Vector2:Sign

**Signature:** `Vector2:Sign(): Vector2`

Returns a new vector from the sign (-1, 0, or 1) of the original's
components. For example, a vector of `(-2.6, 5.1)` returns a vector of
`(-1, 1)`.

**Returns:** `Vector2`

### Vector2:Angle

**Signature:** `Vector2:Angle(other: Vector2, isSigned?: boolean): number`

Returns the angle in radians between the two vectors. Specify `true` for
the optional `isSigned` boolean if you want a signed angle. By default,
the method returns the absolute value. Signed angles are a negative when
going clockwise. Values are in the range `[0, pi]` for absolute angles and
`[-pi, pi]` for signed angles.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `other` | `Vector2` |  |  |
| `isSigned` | `boolean` | `false` |  |

**Returns:** `number`

### Vector2:Dot

**Signature:** `Vector2:Dot(v: Vector2): number`

Returns a scalar dot product of the two vectors.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `v` | `Vector2` |  |  |

**Returns:** `number`

### Vector2:Lerp

**Signature:** `Vector2:Lerp(v: Vector2, alpha: number): Vector2`

Returns a [Vector2](/docs/reference/engine/datatypes/Vector2.md) linearly interpolated between this
[Vector2](/docs/reference/engine/datatypes/Vector2.md) and the given goal by the given alpha.

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `v` | `Vector2` |  |  |
| `alpha` | `number` |  |  |

**Returns:** `Vector2`

### Vector2:Max

**Signature:** `Vector2:Max(others...: Tuple): Vector2`

Returns a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component as the highest among the
respective components of the provided [Vector2](/docs/reference/engine/datatypes/Vector2.md) objects.

```lua
local a = Vector2.new(1, 2)
local b = Vector2.new(2, 1)

print(a:Max(b)) -- Vector2.new(2, 2)
```

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `others...` | `Tuple` |  |  |

**Returns:** `Vector2`

### Vector2:Min

**Signature:** `Vector2:Min(others...: Tuple): Vector2`

Returns a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component as the lowest among the
respective components of the provided [Vector2](/docs/reference/engine/datatypes/Vector2.md) objects.

```lua
local a = Vector2.new(1, 2)
local b = Vector2.new(2, 1)

print(a:Min(b)) -- Vector2.new(1, 1)
```

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `others...` | `Tuple` |  |  |

**Returns:** `Vector2`

### Vector2:FuzzyEq

**Signature:** `Vector2:FuzzyEq(other: Vector2, epsilon?: number): bool`

Returns `true` if the X and Y components of the other [Vector2](/docs/reference/engine/datatypes/Vector2.md)
are within epsilon units of each corresponding component of this
[Vector2](/docs/reference/engine/datatypes/Vector2.md).

**Parameters:**

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `other` | `Vector2` |  |  |
| `epsilon` | `number` | `0.00001 (1e-5)` |  |

**Returns:** `bool`

## Math Operations

| Operation | Type A | Type B | Returns | Description |
|-----------|--------|--------|---------|-------------|
| `+` | `Vector2` | `Vector2` | `Vector2` | Produces a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component of the second added to the corresponding component of the first. |
| `-` | `Vector2` | `Vector2` | `Vector2` | Produces a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component of the second subtracted from the corresponding component of the first. |
| `*` | `Vector2` | `Vector2` | `Vector2` | Produces a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component of the second multiplied by the corresponding component of the first. |
| `/` | `Vector2` | `Vector2` | `Vector2` | Produces a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component of the first divided by the corresponding component of the second. |
| `*` | `Vector2` | `number` | `Vector2` | Produces a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component multiplied by the number. |
| `/` | `Vector2` | `number` | `Vector2` | Produces a [Vector2](/docs/reference/engine/datatypes/Vector2.md) with each component divided by the number. |