vec2
Lens Studio v1.0.0+
Description
A two dimensional vector.
Constructor
new vec2(Number x, Number y)
: vec2
Creates a new instance of a vec2.
Methods
add(vec2 vec)
: vec2
Returns the vector plus vec
.
angleTo(vec2 vec)
: Number
Returns the angle between the vector and vec
.
clampLength(Number length)
: vec2
Returns a copy of the vector with its length clamped to length
.
distance(vec2 vec)
: Number
Returns the distance between the vector and the vector vec
.
div(vec2 vec)
: vec2
Returns the division of the vector by the vector vec
.
dot(vec2 vec)
: Number
Returns the dot product of the vector and vec
.
equal(vec2 vec)
: Boolean
Returns whether this is equal to vec
.
moveTowards(vec2 point, Number magnitude)
: vec2
Returns a copy of the vector moved towards the point point
by the amount magnitude
.
mult(vec2 vec)
: vec2
Returns the component-wise multiplication product of the vector and vec
.
normalize()
: vec2
Returns a copy of the vector with its length scaled to 1.
project(vec2 vec)
: vec2
Returns a copy of the vector projected onto the vector vec
.
projectOnPlane(vec2 normal)
: vec2
Projects the vector onto the plane represented by the normal normal
.
reflect(vec2 vec)
: vec2
Returns a copy of the vector reflected across the plane defined by the normal vec
.
scale(vec2 vec)
: vec2
Returns the component-wise multiplication product of the vector and vec
.
sub(vec2 vec)
: vec2
Returns the vector minus vec
.
toString()
: String
Returns a string representation of the vector.
uniformScale(Number scale)
: vec2
Multiplies the components by the number scale
.
static down()
: vec2
Returns the vector (0, -1).
static left()
: vec2
Returns the vector (-1, 0).
static lerp(vec2 vecA, vec2 vecB, Number t)
: vec2
Linearly interpolates between the two vectors vecA
and vecB
by the factor t
.
static max(vec2 vecA, vec2 vecB)
: vec2
Returns a new vector containing the largest value of each component in the two vectors.
static min(vec2 vecA, vec2 vecB)
: vec2
Returns a new vector containing the smallest value of each component in the two vectors.
static one()
: vec2
Returns the vector (1, 1).
static right()
: vec2
Returns the vector (1, 0).
static up()
: vec2
Returns the vector (0, 1).
static zero()
: vec2
Returns the vector (0, 0).
Properties
g
: Number
Alternate name for the y component.
length
: Number
Returns the length of the vector.
lengthSquared
: Number
Returns the squared length of the vector.
r
: Number
Alternate name for the x component.
x
: Number
x component of the vec2.
y
: Number
y component of the vec2.
Examples
// Set the scale of a sprite using vec2 methods
//@input Component.SpriteAligner spriteAligner
//@input float spriteScale
script.spriteAligner.size = vec2.one().uniformScale(script.spriteScale);
Still Looking for help?
Visit Support