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)
| Field | Type |
|---|---|
| Signature | (x: number, y: number) → Vec2 |
| Returns | Vec2 — point world-unit presisi float |
| Async | no |
Vector2i.new(x, y)
| Field | Type |
|---|---|
| Signature | (x: number, y: number) → Vec2i |
| Returns | Vec2i — point koordinat tile integer |
| Async | no |
local entitySize = Vector2.new(0.32, 0.32)
local tile = Vector2i.new(5, 5)
Field
vec.x / vec.y
| Field | Type |
|---|---|
| Signature | Vec2.x → number / Vec2.y → number (read + write, kedua axis) |
| Returns | number — 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)
| Field | Type |
|---|---|
| Signature | (self: Vec2, size: Vec2) → Vec2i |
| Returns | Vec2i — point tile dari entity ukuran size yang pojok kiri-atasnya nempel di posisi world ini |
| Async | no |
Vec2i:position(size)
| Field | Type |
|---|---|
| Signature | (self: Vec2i, size: Vec2) → Vec2 |
| Returns | Vec2 — pojok kiri-atas world-space dari entity ukuran size yang ditaruh di point tile ini |
| Async | no |
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)
| Field | Type |
|---|---|
| Signature | (self: Vec2, other: Vec2) → boolean (dan varian Vec2i) |
| Returns | boolean — true kalau x dan y sama persis |
| Async | no |
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.