Represents a 2D vector in Among Us, i.e. a position or velocity.

Hierarchy

  • Vector2

Methods

  • Add two vectors together

    Returns

    A new vector with the two vectors added together.

    Example

    const a = new Vector2(5, 8);
    const b = new Vector2(3, 7);

    const c = Vector2.add(a, b);
    console.log(c); // => (8, 15)

    Parameters

    Returns Vector2

  • Clamp a value between a minimum and a maximum.

    Returns

    The clamped value.

    Example

    console.log(Vector2.clamp(50, 0, 100)); // => 50
    console.log(Vector2.clamp(125, 0, 100)); // => 100
    console.log(Vector2.clamp(-50, 0, 100)); // => 0

    Parameters

    • val: number

      The value to clamp.

    • min: number

      The minimum value.

    • max: number

      The maximum value.

    Returns number

  • Calculate the distance between one vector and another.

    Returns

    The distance between the two vectors.

    Example

    const a = new Vector(3, 3);
    const b = new Vector(6, 7);

    const dist = Vector2.dist(a, b);
    console.log(dist); // => 5

    Parameters

    Returns number

  • Divide one vector from another.

    Returns

    A new vector with one vector divided by the other.

    Example

    const a = new Vector2(4, 81);
    const b = new Vector2(2, 9);

    const c = Vector2.div(a, b);
    console.log(c); // => (2, 9)

    Parameters

    Returns Vector2

  • Divide a vector by a scalar value.

    Returns

    A new vector with the vector scaled by the scalar.

    Example

    const a = new Vector(40, 32);
    const c = Vector2.div(a, 8);
    console.log(c); // => (5, 4)

    Parameters

    • a: Vector2

      The vector to scale.

    • b: number

      The scalar.

    Returns Vector2

  • Map a value between 0 and 1 to between a minimum and maximum value.

    Returns

    The lerped value.

    Example

    console.log(Vector2.lerp(0.9)); // => 40
    console.log(Vector2.lerp(0.9, -30, 30)); // => 24

    Parameters

    • val: number

      The value to lerp.

    • Optional min: number

      The minimum value to lerp from.

    • Optional max: number

      The maximum value to lerp to.

    Returns number

  • Multiply one vector with another.

    Returns

    A new vector with the two vectors multiplied together.

    Example

    const a = new Vector2(2, 9);
    const b = new Vector2(2, 9);

    const c = Vector2.mul(a, b);
    console.log(c); // => (4, 81)

    Parameters

    Returns Vector2

  • Scale a vector with a scalar.

    Returns

    A new vector with the vector scaled by the scalar.

    Example

    const a = new Vector(5, 4);
    const c = Vector2.mul(a, 8);
    console.log(c); // => (40, 32)

    Parameters

    • a: Vector2

      The vector to scale.

    • b: number

      The scalar.

    Returns Vector2

  • Parameters

    Returns Vector2

  • Parameters

    Returns Vector2

  • Subtract one vector from another.

    Returns

    A new vector with the second vector subtracted from the first.

    Example

    const a = new Vector2(9, 9);
    const b = new Vector2(3, 3);

    const c = Vector2.sub(a, b);
    console.log(c); // => (6, 6)

    Parameters

    Returns Vector2

  • Map a value between a minimum and maximum value to between 0 and 1.

    Returns

    The unlerped value.

    Example

    console.log(Vector2.unlerp(0)); // => 0.5
    console.log(Vector2.unlerp(0, -15, 25)); // => 0.375

    Parameters

    • val: number

      The value to unlerp.

    • Optional min: number

      The minimum value to unlerp from.

    • Optional max: number

      The maximum value to unlerp to.

    Returns number

  • Parameters

    Returns void

  • Returns Vector2

  • Parameters

    Returns number

  • Parameters

    Returns Vector2

  • Parameters

    • b: number

    Returns Vector2

  • Parameters

    Returns Vector2

  • Parameters

    • b: number

    Returns Vector2

  • Returns Vector2

  • Returns Vector2

  • Parameters

    • radians: number

    Returns Vector2

  • Parameters

    • degrees: number

    Returns Vector2

  • Convert the vector into a string.

    Returns

    The vector as a string.

    Example

    const vector = new Vector2(5, 6);

    console.log(vector.toString()); // => (5, 6)

    Returns string

Accessors

  • get down(): Vector2
  • Returns Vector2

  • get left(): Vector2
  • Returns Vector2

  • get null(): Vector2
  • A null vector.

    Example

    console.log(Vector2.null); // => (0, 0)
    

    Returns Vector2

  • get right(): Vector2
  • Returns Vector2

  • get up(): Vector2
  • Returns Vector2

Constructors

  • Create a 2D Vector from two numbers.

    Example

    const vector = new Vector2(62, 50);
    

    Parameters

    • Optional x: number

      X coordinate of the vector.

    • Optional y: number

      Y coordinate of the vector. Leave out to use the same value as x.

    Returns Vector2

  • Create a 2D vector from a number tuple.

    Example

    const vector = new Vector2([ 60, 70 ]);
    

    Parameters

    • pos: [number, number]

      The X and Y coordinates of the vector.

    Returns Vector2

  • Create a 2D vector from another 2D vector, cloning it.

    Example

    const vector = new Vector2(62, 50);
    const other = new Vector2(other);

    Parameters

    • other: Vector2

      The vector to clone.

    Returns Vector2

  • Create a 2D vector from an object containing an x and y property.

    Example

    const vector = new Vector2({
    x: 50,
    y: 20
    });

    Parameters

    • pos: {
          x: number;
          y: number;
      }

      The object to create from.

      • x: number
      • y: number

    Returns Vector2

Properties

x: number

The X coordinate of the vector.

y: number

The Y coordinate of the vector.

Generated using TypeDoc