Open Asterune
Vector2

Vector2

Represents a 2-component vector.

Behavior

Vector2 stores X, Y components for positions, directions, and dimensions. Components are read-only. Arithmetic returns new vectors; addition is componentwise and multiplication by a number scales the vector.

Summary

Constructors3
Constants2
  • Vector2.one: Vector2

    The vector (1, 1).

  • Vector2.zero: Vector2

    The vector (0, 0).

Functions1
  • Vector2.new(x: number?, y: number?): Vector2

    Creates a vector from X, Y components.

Members6
Properties4
Methods2
  • Dot(other: Vector2): number

    Returns the dot product.

  • Lerp(other: Vector2, alpha: number): Vector2

    Interpolates toward another vector.

Constructors

new

Vector2.new(x: number?, y: number?): Vector2

Creates a vector from X, Y components. Omitted components default to 0.

one

Vector2.one: Vector2

The vector (1, 1).

zero

Vector2.zero: Vector2

The vector (0, 0).

Properties

Magnitude

Vector2.Magnitude: number

The vector length. The magnitude of the difference between two positions is their distance.

Unit

Vector2.Unit: Vector2

Returns a vector with the same direction and length 1. Check for zero magnitude before normalizing.

X

Vector2.X: number

The X component. Read-only.

Y

Vector2.Y: number

The Y component. Read-only.

Methods

Dot

Vector2:Dot(other: Vector2): number

Returns the dot product. For nonzero vectors, a positive result indicates an angle below 90 degrees, 0 indicates perpendicular directions, and a negative result indicates an angle above 90 degrees.

Lerp

Vector2:Lerp(other: Vector2, alpha: number): Vector2

Interpolates toward another vector. A fraction of 0 returns this vector; 1 returns the target vector.

Operators

__add · __div · __eq · __mul · __sub · __tostring · __type · __unm

Example

Luau
local vector = Vector2.new(1, 2)
print(vector.Magnitude)

Used by

BillboardGui · Camera · Frame · Gradient · GuiService · ImageButton · ImageLabel · InputService · LinearVelocity · ProximityPrompt · SceneFrame · ScrollingFrame · Shadow · Stack · SurfaceGui · TextBox · TextButton · TextLabel · TextService · UIGridLayout · UIListLayout · UIPageLayout · UISizeConstraint · VRService

Vector3 · UDim2 · InputObject