Motion
Get Motion

ReferenceScripting APIVector2

Vector2

class

A point or direction in 2D.

NameVector2
Kindclass
Script reaches it asimport { Vector2 } from "motion"
Since0.3

Syntax

class Vector2 { … }

Properties

NameTypeDescription
xpropertynumberAcross.
ypropertynumberDown.
zeropropertyreadonly Vector2(0, 0).
lengthpropertyreadonly numberHow long it is.

Methods

SignatureDescription
new Vector2(x?: number, y?: number): Vector2constructorA new vector.
add(v: Vector2): Vector2methodThis plus another.
sub(v: Vector2): Vector2methodThis less another.
scale(k: number): Vector2methodThis times a number.
dot(v: Vector2): numbermethodThe dot product with another.
normalised(): Vector2methodThe same direction, 1 long (0, 0 for none).
lerp(v: Vector2, t: number): Vector2methodBetween this and another, t of the way.
toArray(): [number, number]methodAs [x, y].