A vector with 2 components, labeled: X, Y.

Constructors

Properties

x: number

The X component of the vector.

y: number

The Y component of the vector.

Methods

  • Scales another vector and adds it to this vector.

    Parameters

    • vector: Readonly<Vector2>

      The vector to add to this vector.

    • scale: number

      The scaling to apply to the input vector.

    Returns this

    This instance.

  • Scales another vector and adds it to this vector.

    Parameters

    • x: number

      The value to add to the X component.

    • y: number

      The value to add to the Y component.

    • scale: number

      The scaling to apply to the input vector.

    Returns this

    This instance.

  • Adds another vector to this vector.

    Parameters

    • x: number

      The value to add to the X component.

    • y: number

      The value to add to the Y component.

    Returns this

    This instance.

  • Return the components of this vector as an array.

    Returns [number, number]

    The components of this vector as an array.

  • Clamps the components of the vector at the given boundary.

    Parameters

    • floor: number

      The lowest value to allow.

    • ceil: number

      The largest value to allow.

    Returns this

    This instance.

  • Divides the vector by the given scale.

    Parameters

    • scale: number

      The scaling to apply to the vector.

    Returns this

    This instance.

  • Divides this vector by another vector.

    Parameters

    • x: number

      The value to divide the X component with.

    • y: number

      The value to divide the Y component with.

    Returns this

    This instance.

  • Returns the dot product between two vectors.

    Parameters

    • x: number

      The X component of the other vector.

    • y: number

      The Y component of the other vector.

    Returns number

    The dot product between the two vectors.

  • Calculates the length of the vector.

    Returns number

    The length of the vector.

  • Multiplies the vector by the given scale.

    Parameters

    • scale: number

      The scaling to apply to the vector.

    Returns this

    This instance.

  • Multiplies this vector by another vector.

    Parameters

    • x: number

      The value to multiply with the X component.

    • y: number

      The value to multiply with the Y component.

    Returns this

    This instance.

  • Rotates the vector by the given angle.

    Parameters

    • angle: number

      The angle in degrees.

    Returns this

    This instance.

  • Sets the vector to new coordinates.

    Parameters

    • x: number

      The new X component for the vector.

    • y: number

      The new Y component for the vector.

    Returns this

    This instance.

  • Subtracts another vector from this vector.

    Parameters

    • x: number

      The value to subtract from the X component.

    • y: number

      The value to subtract from the Y component.

    Returns this

    This instance.