Skip to main content

Vector2 & Vector2i

Two coordinate primitives the bot passes around for any spatial argument:

  • Vector2 — float-precision world position (sub-tile resolution, e.g. client:position()).
  • Vector2i — integer tile point (e.g. client:point(), world:tile(point)).

Tile size is 0.32 world units, so world ↔ tile round-trips through that constant.

local point = Vector2i.new(5, 5)
local position = Vector2.new(5.3, 8.7)

Constructors

Vector2.new(x, y)

FieldType
Signature(x: number, y: number) → Vec2
ReturnsVec2 — float-precision world-unit point
Asyncno

Vector2i.new(x, y)

FieldType
Signature(x: number, y: number) → Vec2i
ReturnsVec2i — integer tile-coord point
Asyncno
local entitySize = Vector2.new(0.32, 0.32)
local tile = Vector2i.new(5, 5)

Fields

vec.x / vec.y

FieldType
SignatureVec2.x → number / Vec2.y → number (read + write, both axes)
Returnsnumber — float for Vec2, integer for Vec2i

Both axes are mutable — write back to update the value in place.

local p = Vector2i.new(5, 5)
p.x -- 5
p.y -- 5
p.x = p.x + 1

Methods

Vec2:point(size)

FieldType
Signature(self: Vec2, size: Vec2) → Vec2i
ReturnsVec2i — tile point of an entity of size whose top-left corner sits at this world position
Asyncno

Vec2i:position(size)

FieldType
Signature(self: Vec2i, size: Vec2) → Vec2
ReturnsVec2 — world-space top-left corner of an entity of size placed at this tile point
Asyncno

Vec2:point and Vec2i:position round-trip through TILE_SIZE = 0.32 and the half-tile center offset, so tile:position(size):point(size) returns the original tile.

local entitySize = Vector2.new(0.32, 0.32)

local point = Vector2i.new(5, 5)
point:position(entitySize) -- world position scaled to the entity size

local position = Vector2.new(5.3, 8.7)
position:point(entitySize) -- nearest tile point at that entity size

Vec2:equals(other) / Vec2i:equals(other)

FieldType
Signature(self: Vec2, other: Vec2) → boolean (and the Vec2i variant)
Returnsbooleantrue when both x and y match exactly
Asyncno

Both types also implement the == metamethod, so a == b and a:equals(b) are interchangeable.

Vector2i.new(5, 5):equals(Vector2i.new(5, 5)) -- true
Vector2.new(1.0, 2.0) == Vector2.new(1.0, 2.0) -- true

Mostly used to feed client:setPoint, client:findPath, world:tile, client:hit, etc.