> For the complete documentation index, see [llms.txt](https://fehdead.gitbook.io/npc-kit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/atan2.md).

# npc.atan2

```lua
npc.atan2(y, x)
```

|                         |                                                                        |
| ----------------------- | ---------------------------------------------------------------------- |
| id                      | `0x0294`                                                               |
| arguments               | 2: Float, Float                                                        |
| result                  | float: goes to the very next call, or to `npc.lua(npc.atan2(...), fn)` |
| in NPC Kit              | yes                                                                    |
| measured from a kit NPC | returns                                                                |
| vanilla scripts         | 265 calls in 22 of 1114 scripts                                        |

## What it does

Gives `atan2(y, x)` in radians. A result.

## Arguments

### `y` (Float)

### `x` (Float)

## Result

The angle, a float.

## Timing

Returns at once.

## In NPC Kit

Use Lua's `math.atan(y, x)` when `npc.add` runs: the VM's result can only feed the next call. For a heading from one point to another the kit form is `math.atan(to[1] - from[1], to[3] - from[3])`.

## Used with

* [dir](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/dir.md), [aturn\_261](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/aturn_261.md).

## Example

The heading from the NPC to a point, computed in Lua when `npc.add` runs:

```lua
local function heading(from, to)
    return math.atan(to[1] - from[1], to[3] - from[3])
end

local owner, leader = { 321.496, 2.022, 41.714 }, { 320.780, 2.022, 43.140 }

open = function()
    npc.dir(heading(owner, leader));   -- faces the leader's mark
end,
```
