# Vec2

### Properties

* <mark style="color:purple;">`x`</mark> - double
* <mark style="color:purple;">`y`</mark> - double

### Methods

* [constructor](#vec2-new-x-y)
* [length](#length)
* [distanceTo](#distanceto-othervec2)
* [angleTo](#angleto-othervec2)
* [normalized](#normalized)
* [scale](#scale-scalar)

### <mark style="color:green;">`Vec2:new(x, y)`</mark>

* <mark style="color:purple;">`x`</mark> - What to set x to
* <mark style="color:purple;">`y`</mark> - What to set y to&#x20;

Constructs a new Vec2 with the provided x and y.

**Example:**

```lua
local screenPosition = Vec2:new(200, 200)
```

### <mark style="color:green;">`length()`</mark>

Returns the length of the Vec2&#x20;

**Example:**

```lua
local vec = Vec2:new(200, 200)
print("The vector has a length of " .. vecL:length())
```

### <mark style="color:green;">`distanceTo(otherVec2)`</mark>

* <mark style="color:purple;">`otherVec2`</mark> - A different Vec2&#x20;

Returns the distance from this vector to the `otherVec2`

**Example:**

```lua
local vecA = Vec2:new(200, 200)
local vecB = Vec2:new(400, 690)
print("Distance from vecA to vecB: " .. vecA:distanceTo(vecB))
```

### <mark style="color:green;">`angleTo(otherVec2)`</mark>

* <mark style="color:purple;">`otherVec2`</mark> - A different Vec2&#x20;

Returns the angle to the `otherVec2`

**Example:**

```lua
local vecA = Vec2:new(1, 0)
local vecB = Vec2:new(0, 1)
print("Angle between vecA and vecB: " .. vecA:angleTo(vecB)) --prints 90
```

### <mark style="color:green;">`normalized()`</mark>

Returns this vector but normalized (that is with length 1)

**Example:**

```lua
local vecA = Vec2:new(20, 10)
print("vecA normalized: " .. vecA:normalized():toString()) --prints (0.8944, 0.4472)
```

### <mark style="color:green;">`scale(scalar)`</mark>

* <mark style="color:purple;">`scalar`</mark> - By how much you want to scale the vector

Returns a scaled version of this vector

**Example:**

```lua
local vecA = Vec2:new(20, 10)
print("vecA scaled by 2: " .. vecA:scale(2):toString()) --prints (40, 20)
```

### <mark style="color:green;">`toString()`</mark>

Returns a string representation of the Vec2

**Example:**

```lua
local vecA = Vec2:new(20, 10)
print("vecA: " .. vecA:toString()) --prints (20, 10)
```


---

# 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.anvil.team/types/vec2.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.
