Lewati ke konten utama

Vector2 & Vector2i

Dua primitif koordinat yang dilempar bot buat argumen spasial apapun:

  • Vector2 — posisi dunia presisi float (resolusi sub-tile, mis. client:position()).
  • Vector2i — point tile integer (mis. client:point(), world:tile(point)).

Ukuran tile = 0.32 world unit, jadi konversi world ↔ tile round-trip lewat konstanta itu.

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

Constructor

Vector2.new(x, y)

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

Vector2i.new(x, y)

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

Field

vec.x / vec.y

FieldType
SignatureVec2.x → number / Vec2.y → number (read + write, kedua axis)
Returnsnumber — float buat Vec2, integer buat Vec2i

Kedua axis mutable — tulis balik buat update value-nya in place.

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

Method

Vec2:point(size)

FieldType
Signature(self: Vec2, size: Vec2) → Vec2i
ReturnsVec2i — point tile dari entity ukuran size yang pojok kiri-atasnya nempel di posisi world ini
Asyncno

Vec2i:position(size)

FieldType
Signature(self: Vec2i, size: Vec2) → Vec2
ReturnsVec2 — pojok kiri-atas world-space dari entity ukuran size yang ditaruh di point tile ini
Asyncno

Vec2:point dan Vec2i:position round-trip lewat TILE_SIZE = 0.32 plus offset center setengah-tile, jadi tile:position(size):point(size) ngembaliin tile awal.

local entitySize = Vector2.new(0.32, 0.32)

local point = Vector2i.new(5, 5)
point:position(entitySize) -- posisi peta diskala ke ukuran entity

local position = Vector2.new(5.3, 8.7)
position:point(entitySize) -- point tile terdekat di ukuran entity itu

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

FieldType
Signature(self: Vec2, other: Vec2) → boolean (dan varian Vec2i)
Returnsbooleantrue kalau x dan y sama persis
Asyncno

Kedua tipe juga implement metamethod ==, jadi a == b dan a:equals(b) itu interchangeable.

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

Sering dipakai sebagai input ke client:setPoint, client:findPath, world:tile, client:hit, dst.