Skip to content

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

Function
new(x: number, y: number) -> Vector2

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

PropertyRead only
Zero: Vector2

Vector2.Zero is the 2D vector (0, 0).

Default Vector2.new(0, 0)

One

PropertyRead only
One: Vector2

Vector2.One is the 2D vector (1, 1).

Default Vector2.new(1, 1)

XAxis

PropertyRead only
XAxis: Vector2

Vector2.XAxis is the unit 2D vector (1, 0).

Default Vector2.new(1, 0)

YAxis

PropertyRead only
YAxis: Vector2

Vector2.YAxis is the unit 2D vector (0, 1).

Default Vector2.new(0, 1)