@panda0day/fivex
    Preparing search index...

    Class Vector3

    An immutable-by-convention 3D vector with common math operations.

    Every operation returns a new Vector3 rather than mutating in place, so instances are safe to share. Because the public x/y/z fields satisfy IVector3, an instance can be passed directly to any native that expects a coordinate shape (e.g. SetEntityCoords).

    const a = new Vector3(0, 0, 0);
    const b = new Vector3(10, 0, 0);

    a.distanceTo(b); // 10
    a.lerp(b, 0.5); // Vector3(5, 0, 0)
    a.add(new Vector3(0, 0, 5)); // Vector3(0, 0, 5)

    Implements

    Index
    • Creates a vector from its components.

      Parameters

      • x: number = 0

        X component.

      • y: number = 0

        Y component.

      • z: number = 0

        Z component.

      Returns Vector3

      0
      
      0
      
      0
      
    x: number = 0

    X component.

    y: number = 0

    Y component.

    z: number = 0

    Z component.

    • get length(): number

      The magnitude (Euclidean length) of the vector.

      Returns number

      Involves a square root. If you only need to compare magnitudes, prefer Vector3.lengthSquared to avoid the Math.sqrt call.

    • get lengthSquared(): number

      The squared magnitude of the vector.

      Returns number

      Cheaper than Vector3.length because it skips the square root. Order is preserved, so it is ideal for "which is closer" comparisons.

    • Squared Euclidean distance to another point.

      Parameters

      Returns number

      The squared distance.

      Skips the square root, so use this when ranking or thresholding distances (compare against a squared radius) rather than reporting an actual distance.

    • Dot product with another vector.

      Parameters

      Returns number

      The scalar dot product. 0 means the vectors are perpendicular.

    • Compares two vectors for approximate equality.

      Parameters

      • v: Vector3

        The vector to compare against.

      • epsilon: number = 1e-6

        Maximum allowed per-component difference.

      Returns boolean

      true if every component is within epsilon of v.

      Uses a tolerance because floating-point math rarely produces exactly equal components after arithmetic.

      1e-6
      
    • Linearly interpolates from this vector toward another.

      Parameters

      • v: Vector3

        The target vector.

      • t: number

        Interpolation factor. 0 returns this vector, 1 returns v; values outside [0, 1] extrapolate.

      Returns Vector3

      The interpolated vector.

    • Multiplies this vector by a vector or a scalar.

      Parameters

      • value: number | Vector3

        A Vector3 (component-wise) or a number (scales every component).

      Returns Vector3

      The resulting vector.

      Vector input is a component-wise (Hadamard) product, not a dot or cross product. Pass a scalar to uniformly scale — e.g. v.multiply(2) doubles the length.

    • Subtracts a vector or a scalar from this vector.

      Parameters

      • value: number | Vector3

        A Vector3 (component-wise) or a number (subtracted from every component).

      Returns Vector3

      The resulting vector.

    • Converts to a plain [x, y, z] tuple.

      Returns [number, number, number]

      The components as a fixed-length array.

    • A human-readable representation, e.g. "Vector3(1, 2, 3)".

      Returns string

      The formatted string.

    • Builds a Vector3 from a plain object or a [x, y, z] tuple.

      Parameters

      • value: number[] | IVector3

        Either an { x, y, z } object or a numeric array in [x, y, z] order.

      Returns Vector3

      A new Vector3.

      Vector3.from({ x: 1, y: 2, z: 3 });
      Vector3.from(GetEntityCoords(ped, true)); // wrap a native result
      Vector3.from([1, 2, 3]);