Vector2

Overview

Vector2 is a data type used to express vector in a two-dimensional space using X and Y axes. It is used to handle a variety of 2D data such as position, direction, speed, and strength. It is also one of the key elements used by many systems to calculate coordinates and vector within a space or simulating 2D physics.

Constructors

new

Creates and returns a new vector using the passed X and Y values.

Parameters

number x

The value of X coordinate.

number y

The value of Y coordinate.

Return

Vector2

The created Vector2.

Code Samples

local Vector = Vector2.new(3, 7)
print(Vector)

Properties

X

number

The value of X coordinate.

Code Samples

Y

number

The value of Y coordinate.

Code Samples

zero

Vector2

A vector of which axis values are zeroes (0, 0).

Code Samples

one

Vector2

A vector of which axis values are ones (1, 1).

Code Samples

xAxis

Vector2

A Vector2 set to have the value of 1 for X axis and 0 for Y axis (1, 0).

Code Samples

yAxis

Vector2

A Vector2 set to have the value of 0 for X axis and 1 for Y axis (0, 1).

Code Samples

Methods

Lerp

Calculates the linear interpolation between the current vector and the target vector according to alpha ratio and returns it as a new vector.

Parameters

Vector2 goal

The target Vector2 to be interpolated.

number alpha

A value indicating interpolation ratio.

Return

Vector2

The created Vector2.

Code Samples

Slerp

Calculates the spherical linear interpolation between the current vector and the target vector according to alpha ratio and returns it as a new vector.

While Lerp interpolates along a linear path, Slerp interpolates along a curve on a unit sphere, making its rotation axis movement smoother and more constant.

Parameters

Vector2 goal

The target Vector2 to be interpolated.

number alpha

A value indicating interpolation ratio.

Return

Vector2

The created Vector2.

Code Samples

Last updated