> For the complete documentation index, see [llms.txt](https://docs.autowall.fun/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.autowall.fun/documentation/vars/vector.md).

# Vector

## <i class="fa-draw-polygon">:draw-polygon:</i> Vector

`vector(x, y, z)` is a plain Lua table with a metatable (defined in the Lua-side prelude that's injected into every script before it runs) — not a C userdata. Field access (`v.x`) and all methods below work as documented.

```lua
local a = vector(1, 2, 3)
local b = vector(4, 5, 6)

a.x, a.y, a.z         -- direct field access

a:clone()             -- new vector, same values
a:unpack()             -- x, y, z
a:init(7, 8, 9)        -- mutate in place

a:length()             -- number
a:length_sqr()         -- number, cheaper (no sqrt)
a:dist(b)              -- number
a:dist_to(b)           -- alias of :dist()
a:normalize()          -- new unit-length vector (returns vector(0,0,0) if length is 0)
a:dot(b)               -- number
a:cross(b)             -- new vector
a:lerp(b, 0.5)         -- new vector, linear interpolation

a + b                  -- vector
a - b                  -- vector
a * 2                  -- vector (scalar only, either operand order)
a == b                  -- componentwise equality
tostring(a)             -- "vector(1.000, 2.000, 3.000)"
```

{% hint style="warning" %}
`vector * vector` is **not** defined — use `:dot()` or `:cross()` explicitly; it raises a Lua error if you try.
{% endhint %}

#### Where you get vectors from

`entity.get_origin(player)` and the `origin` field on `entity.get_players()` entries return real `vector` objects (see Entity) — they're not a separate type, so all the methods above work on them directly.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.autowall.fun/documentation/vars/vector.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
