Vector4

Reference

class Vector4
module:
x: number
y: number
z: number
w: number
static new(x, y, z, w)

Create new vector

Parameters:
  • x (number) – x component

  • y (number) – y component

  • z (number) – z component

  • w (number) – w component

Returns:

new vector

Return type:

Vector4

set(x, y, z, w)

Set components of the vector

Parameters:
  • x (number) – x component

  • y (number) – y component

  • z (number) – z component

  • w (number) – w component

get()

Return the 4 components as array

Returns:

the 4 components

Return type:

array

static lerp(from, to, t)

Linear interpolation between 2 vectors

Parameters:
  • from (Vector4) – first vector

  • to (Vector4) – second vector

  • t (number) – position between those vectors from 0 to 1

Returns:

interpolated vector

Return type:

Vector4

static moveTowards(current, target, maxDistanceDelta)

Move one vector in the direction of the target vector

Parameters:
  • current (Vector4) – current position

  • target (Vector4) – target position

  • maxDistanceDelta (number) – maximum distance to move towards target

Returns:

returns a new vector

Return type:

Vector4

static scaled(a, b)

Scale vector by another vector

Parameters:
Returns:

new scaled vector

Return type:

Vector4

scale(scale)

Scale this vector by another vector

Parameters:

scale (Vector4) – scale vector

Returns:

returns itself

Return type:

Vector4

normalized()

Return normalized version of this vector

Returns:

normalized vector

Return type:

Vector4

normalize()

Normalize this vector

Returns:

returns itself

Return type:

Vector4

div(d)

Device this vector by another one

Parameters:

d (Vector4) – other vector

Returns:

returns itself

Return type:

Vector4

mul(d)

Multiply this vector with another one

Parameters:

d (Vector4) – other vector

Returns:

returns itself

Return type:

Vector4

add(b)

Add another vector to this vector

Parameters:

b (Vector4) – other vector

Returns:

returns itself

Return type:

Vector4

sub(b)

Subtract another vector from this one

Parameters:

b (Vector4) – other vector

Returns:

returns itself

Return type:

Vector4

static dot(a, b)

Calculates dot product from 2 vectors

Parameters:
Returns:

the dot product

Return type:

number

static project(a, b)

Project one vector onto another

Parameters:
Returns:

projected vector

Return type:

Vector4

static distance(a, b)

Calculate distance between 2 vectors

Parameters:
Returns:

distance

Return type:

number

magnitude()

Calculate magnitude of the vector

Returns:

magnitude

Return type:

number

sqrMagnitude()

Calculate squared magnitude of the vector

Returns:

squared magnitude

Return type:

number

static min(lhs, rhs)

Return the minimum of all components of two vectors into a new vector

Parameters:
Returns:

minimum vector

Return type:

Vector4

static max(lhs, rhs)

Return the maximum of all components of two vectors into a new vector

Parameters:
Returns:

maximum vector

Return type:

Vector4

Examples