Skip to content

Vec2

Properties

  • x (number): X component
  • y (number): Y component

Functions

  • Angle(): Vec2.Angle(a, b): angle between two vectors, in radians
  • Clamp(): Shorten this vector in place to at most the given length
  • Cross(): Vec2.Cross(a, b): 2D cross product
  • Distance(): Vec2.Distance(a, b): distance between two points
  • Dot(): Vec2.Dot(a, b): dot product
  • Length(): Get the vector's length
  • Lerp(): Vec2.Lerp(a, b, alpha): blend from a to b
  • Normalize(): Scale this vector to length 1, in place
  • Perpendicular(): Get the vector rotated 90 degrees: Perpendicular(clockwise)
  • Reflect(): Vec2.Reflect(v, normal): bounce a vector off a surface
  • SqrDistance(): Vec2.SqrDistance(a, b): squared distance between two points
  • SqrLength(): Get the squared length, cheaper than Length for comparisons
  • Zero(): Set this vector to 0, 0 in place
  • new(): Vec2.new(x, y), or Vec2.new() for 0, 0. Supports +, - and * by a number