Skip to content

types.vector2

A 2D vector

Properties

NameDescription
xtype: number The x component
ytype: number The y component

Functions

new(opt_x : number, opt_y : number): types.vector2

Creates a new 2D vector

  • opt_x (number) (optional) The x component
  • opt_y (number) (optional) The y component
  • returns (types.vector2) A new vector instance

add(other : types.vector2): types.vector2

Adds another vector to this one and returns a new vector

sub(other : types.vector2): types.vector2

Subtracts another vector from this one and returns a new vector

mul(other : types.vector2 | number): types.vector2

Multiplies this vector by another vector or a number and returns a new vector

div(other : types.vector2 | number): types.vector2

Divides this vector by another vector or a number and returns a new vector

dist(other : types.vector2): number

Returns the distance between this vector and another

  • other (types.vector2) The other vector
  • returns (number) The distance

length(): number

Returns the length of this vector

  • returns (number) The length

dot(other : types.vector2): number

Returns the dot product of this vector and another

  • other (types.vector2) The other vector
  • returns (number) The dot product

normalize(): types.vector2

Returns a normalized (unit length) version of this vector