# Vector2

## Overview

Vector2 is a data type used to express vector in a two-dimensional space using X and Y axes. It is used to handle a variety of 2D data such as position, direction, speed, and strength. It is also one of the key elements used by many systems to calculate coordinates and vector within a space or simulating 2D physics.

## Constructors

### new

Creates and returns a new vector using the passed X and Y values.

#### Parameters

| `number` x | The value of X coordinate. |
| ---------- | -------------------------- |
| `number` y | The value of Y coordinate. |

#### Return

| `Vector2` | The created Vector2. |
| --------- | -------------------- |

#### Code Samples

```lua
local Vector = Vector2.new(3, 7)
print(Vector)
```

## Properties

### one

`Vector2`

A vector of which axis values are ones (1, 1).

#### Code Samples

```lua
local OneVector = Vector2.one
print(OneVector)
```

### X

`number`

The value of X coordinate.

#### Code Samples

```lua
local Vector = Vector2.new(5, 10)
print(Vector.X)
```

### xAxis

`Vector2`

A Vector2 set to have the value of 1 for X axis and 0 for Y axis (1, 0).

#### Code Samples

```lua
local XAxis = Vector2.xAxis
print(XAxis)
```

### Y

`number`

The value of Y coordinate.

#### Code Samples

```lua
local Vector = Vector2.new(5, 10)
print(Vector.Y)
```

### yAxis

`Vector2`

A Vector2 set to have the value of 0 for X axis and 1 for Y axis (0, 1).

#### Code Samples

```lua
local YAxis = Vector2.yAxis
print(YAxis)
```

### zero

`Vector2`

A vector of which axis values are zeroes (0, 0).

#### Code Samples

```lua
local ZeroVector = Vector2.zero
print(ZeroVector)
```

## Methods

### Lerp

Calculates the linear interpolation between the current vector and the target vector according to alpha ratio and returns it as a new vector.

#### Parameters

| `Vector2` GoalValue | The target Vector2 to be interpolated.  |
| ------------------- | --------------------------------------- |
| `number` Alpha      | A value indicating interpolation ratio. |

#### Return

| `Vector2` | The created Vector2. |
| --------- | -------------------- |

#### Code Samples

```lua
local a = Vector2.new(0, 0)
local b = Vector2.new(10, 10)
print("Lerp:", a:Lerp(b, 0.3)) --> Output: 3, 3
```

### Slerp

Calculates the spherical linear interpolation between the current vector and the target vector according to alpha ratio and returns it as a new vector.

While Lerp interpolates along a linear path, Slerp interpolates along a curve on a unit sphere, making its rotation axis movement smoother and more constant.

#### Parameters

| `Vector2` GoalValue | The target Vector2 to be interpolated.  |
| ------------------- | --------------------------------------- |
| `number` Alpha      | A value indicating interpolation ratio. |

#### Return

| `Vector2` | The created Vector2. |
| --------- | -------------------- |

#### Code Samples

```lua
local a = Vector2.new(1, 0)
local b = Vector2.new(0, 1)
print("Slerp:", a:Slerp(b, 0.5)) --> Output: 0.707107, 0.707107
```

## Events


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.overdare.com/development/api-reference/datatype/vector2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
