Vector2¶
Global · Vector2 · server and client scripts
Vector2 creates immutable 2D vectors for interface coordinates, anchors, and texture coordinates. Read X, Y, Magnitude, and Unit, call :Dot and :Lerp, and combine vectors with +, -, *, /, //, and unary -.
new¶
Vector2.new creates a 2D vector from x and y.
Example
-- Client script: a label centered on the screen.
local hud = World.Spawn({ UIRoot = true })
hud.Parent = World.Viewport.Screen
local label = World.Spawn({
Box = {
AnchorPoint = Vector2.new(0.5, 0.5),
Position = UIVector.fromScale(0.5, 0.5),
},
UITextSource = { Text = "Ready?" },
})
label.Parent = hud
Zero¶
Vector2.Zero is the 2D vector (0, 0).
Default Vector2.new(0, 0)
One¶
Vector2.One is the 2D vector (1, 1).
Default Vector2.new(1, 1)
XAxis¶
Vector2.XAxis is the unit 2D vector (1, 0).
Default Vector2.new(1, 0)
YAxis¶
Vector2.YAxis is the unit 2D vector (0, 1).
Default Vector2.new(0, 1)