• Studio

  • Bots

  • Web API

  • Designer Resources

  • Host Resources

  • API

    Datatypes

    Edit

    Vector4

    Represents a vector or a point in four-dimensional space, commonly used for RGBA values, 4D transforms, or 3D transformations with homogeneous coordinates.

    Properties

    Provides a normalized version of the Vector4, with a length of 1, useful for direction-only applications.

    local v1 = Vector4.new(1, 2, 3, 4)
    local v2 = v1.normalized
    
    print(v2.x, v2.y, v2.z, v2.w)  -- 0.1826, 0.3651, 0.5477, 0.7303
    

    magnitude

    number

    Provides the length of the Vector4, useful for distance calculations or scaling vectors.

      local v1 = Vector4.new(1, 2, 3, 4)
      print(v1.magnitude)  -- 5.4772
    

    Returns the square of the magnitude of the Vector4, a performance-friendly alternative for length comparisons.

      local v1 = Vector4.new(1, 2, 3, 4)
      print(v1.sqrMagnitude)  -- 30
    

    x

    number

    Accesses the 'x' component of the Vector4, representing different dimensions or the 'Red' component in RGBA.

      local v1 = Vector4.new(1, 2, 3, 4)
      print(v1.x)  -- 1
    

    y

    number

    Accesses the 'y' component of the Vector4, representing different dimensions or the 'Green' component in RGBA.

      local v1 = Vector4.new(1, 2, 3, 4)
      print(v1.y)  -- 2
    

    z

    number

    Accesses the 'z' component of the Vector4, representing different dimensions or the 'Blue' component in RGBA.

      local v1 = Vector4.new(1, 2, 3, 4)
      print(v1.z)  -- 3
    

    w

    number

    Accesses the 'w' component of the Vector4, representing different dimensions or the 'Alpha' component in RGBA.

      local v1 = Vector4.new(1, 2, 3, 4)
      print(v1.w)  -- 4
    

    Represents a Vector4 with all components set to zero.

      local v1 = Vector4.zero
      print(v1.x, v1.y, v1.z, v1.w)  -- 0, 0, 0, 0
    

    Represents a Vector4 with all components set to one, useful for certain mathematical operations.

      local v1 = Vector4.one
      print(v1.x, v1.y, v1.z, v1.w)  -- 1, 1, 1, 1
    

    Represents a Vector4 with all components set to positive infinity, useful for setting maximum limits.

      local v1 = Vector4.positiveInfinity
      print(v1.x, v1.y, v1.z, v1.w)  -- inf, inf, inf, inf
    

    Represents a Vector4 with all components set to negative infinity, useful for setting minimum limits.

      local v1 = Vector4.negativeInfinity
      print(v1.x, v1.y, v1.z, v1.w)  -- -inf, -inf, -inf, -inf
    

    kEpsilon

    number

    Represents a tiny positive number close to zero, used to handle calculations related to precision.

      local v1 = Vector4.kEpsilon
      print(v1.x, v1.y, v1.z, v1.w)  -- 1e-05, 1e-05, 1e-05, 1e-05
    

    Methods

    Sets the 'x', 'y', 'z', and 'w' components of the Vector4, enhancing code readability and efficiency.

      local v1 = Vector4.new(1, 2, 3, 4)
      v1:Set(5, 6, 7, 8)
    
      print(v1.x, v1.y, v1.z, v1.w)  -- 5, 6, 7, 8
    

    Parameters

    newX

    number

    The new 'x' component.

    newY

    number

    The new 'y' component.

    newZ

    number

    The new 'z' component.

    newW

    number

    The new 'w' component.

    Returns

    void

    Scales a Vector4 by another Vector4's components, useful for dimension or shape scaling.

      local v1 = Vector4.new(1, 2, 3, 4)
      local v2 = Vector4.new(2, 3, 4, 5)
      v1:Scale(v2)
    
      print(v1.x, v1.y, v1.z, v1.w)  -- 2, 6, 12, 20
    

    Parameters

    scale
    Vector4

    The Vector4 to scale by.

    Returns

    void

    Transforms the Vector4 into a vector of same direction but with length 1, ideal for direction-only uses.

      local v1 = Vector4.new(1, 2, 3, 4)
      v1:Normalize()
    
      print(v1.x, v1.y, v1.z, v1.w)  -- 0.1826, 0.3651, 0.5477, 0.7303
    

    Returns

    void

    Provides the square of the magnitude of the Vector4, an efficient method for length comparisons.

      local v1 = Vector4.new(1, 2, 3, 4)
      print(v1:SqrMagnitude())  -- 30
    

    Returns

    number

    Returns the square of the magnitude.

    Performs Linear Interpolation between two Vector4's based on a parameter 't', useful for smooth transitions.

      local v1 = Vector4.new(1, 2, 3, 4)
      local v2 = Vector4.new(5, 6, 7, 8)
      local v3 = Vector4.Lerp(v1, v2, 0.5)
    
      print(v3.x, v3.y, v3.z, v3.w)  -- 3, 4, 5, 6
    

    Parameters

    The starting Vector4.

    The ending Vector4.

    t

    number

    The interpolation factor.

    Returns

    Vector4

    Returns an interpolated Vector4.

    Similar to 'Lerp' but without clamping the 't' parameter, offering more freedom in interpolation.

      local v1 = Vector4.new(1, 2, 3, 4)
      local v2 = Vector4.new(5, 6, 7, 8)
      local v3 = Vector4.LerpUnclamped(v1, v2, 2)
    
      print(v3.x, v3.y, v3.z, v3.w)  -- 9, 10, 11, 12
    

    Parameters

    The start Vector4.

    The end Vector4.

    t

    number

    The interpolation fraction.

    Returns

    Vector4

    Returns an unclamped interpolated Vector4.

    Moves a Vector4 'current' towards 'target', limited by 'maxDistanceDelta', useful for smooth object movement.

      local v1 = Vector4.new(1, 2, 3, 4)
      local v2 = Vector4.new(5, 6, 7, 8)
      local v3 = Vector4.MoveTowards(v1, v2, 2)
    
      print(v3.x, v3.y, v3.z, v3.w)  -- 3, 4, 5, 6
    

    Parameters

    current
    Vector4

    The current position.

    target
    Vector4

    The target position.

    maxDistanceDelta

    number

    The max distance to move.

    Returns

    Vector4

    Returns a Vector4 closer to the target.

    Multiplies two Vector4's component-wise, useful for component-wise data manipulation.

      local v1 = Vector4.new(1, 2, 3, 4)
      local v2 = Vector4.new(2, 3, 4, 5)
      local v3 = Vector4.Scale(v1, v2)
    
      print(v3.x, v3.y, v3.z, v3.w)  -- 2, 6, 12, 20
    

    Parameters

    The first Vector4.

    The second Vector4.

    Returns

    Vector4

    Returns a new Vector4 from component-wise multiplication.

    Normalizes a Vector4 and returns a new Vector4 with length 1, ideal for direction-only vectors.

      local v1 = Vector4.new(1, 2, 3, 4)
      local v2 = Vector4.Normalize(v1)
    
      print(v2.x, v2.y, v2.z, v2.w)  -- 0.1826, 0.3651, 0.5477, 0.7303
    

    Parameters

    The Vector4 to normalize.

    Returns

    Vector4

    Returns a normalized Vector4.

    Computes the dot product of two Vector4's, reflecting their angular relationship.

      local v1 = Vector4.new(1, 2, 3, 4)
      local v2 = Vector4.new(5, 6, 7, 8)
      local dotProduct = Vector4.Dot(v1, v2)
    
      print(dotProduct)  -- 70
    

    Parameters

    The first Vector4.

    The second Vector4.

    Returns

    number

    Returns the dot product.

    Projects a Vector4 onto another Vector4, useful for finding the nearest point on a defined line.

      local v1 = Vector4.new(1, 2, 3, 4)
      local v2 = Vector4.new(5, 6, 7, 8)
      local v3 = Vector4.Project(v1, v2)
    
      print(v3.x, v3.y, v3.z, v3.w)  -- 2.5, 3, 3.5, 4
    

    Parameters

    The Vector4 to project.

    The Vector4 to project onto.

    Returns

    Vector4

    Returns the projection of 'a' onto 'b'.

    Computes the distance between two Vector4's, useful for object spacing or collision detection.

      local v1 = Vector4.new(1, 2, 3, 4)
      local v2 = Vector4.new(5, 6, 7, 8)
      local distance = Vector4.Distance(v1, v2)
    
      print(distance)  -- 8.0
    

    Parameters

    The first Vector4.

    The second Vector4.

    Returns

    number

    Returns the distance between the two Vector4's.

    Calculates the length of the Vector4, useful for finding the distance it spans in 4D space.

      local v1 = Vector4.new(1, 2, 3, 4)
      local magnitude = Vector4.Magnitude(v1)
    
      print(magnitude)  -- 5.4772
    

    Parameters

    The Vector4 to compute the magnitude for.

    Returns

    number

    Returns the magnitude of the Vector4.

    Returns a Vector4 with the smallest components of two Vector4's, useful for bounding box operations.

      local v1 = Vector4.new(1, 2, 3, 4)
      local v2 = Vector4.new(5, 6, 7, 8)
      local v3 = Vector4.Min(v1, v2)
    
      print(v3.x, v3.y, v3.z, v3.w)  -- 1, 2, 3, 4
    

    Parameters

    The first Vector4.

    The second Vector4.

    Returns

    Vector4

    Returns a Vector4 with the smallest components.

    Returns a Vector4 with the largest components of two Vector4's, useful for limiting operations.

      local v1 = Vector4.new(1, 2, 3, 4)
      local v2 = Vector4.new(5, 6, 7, 8)
      local v3 = Vector4.Max(v1, v2)
    
      print(v3.x, v3.y, v3.z, v3.w)  -- 5, 6, 7, 8
    

    Parameters

    The first Vector4.

    The second Vector4.

    Returns

    Vector4

    Returns a Vector4 with the largest components.

    Gives the square of the magnitude of a Vector4, an efficient comparison method that avoids square root calculations.

      local v1 = Vector4.new(1, 2, 3, 4)
      local sqrMagnitude = Vector4.SqrMagnitude(v1)
    
      print(sqrMagnitude)  -- 30
    

    Parameters

    The Vector4 to square the magnitude of.

    Returns

    number

    Returns the square of the Vector4's magnitude.

    Updated about 2 months ago

    PocketWorlds Icon

    © 2024 Pocket Worlds. All rights reserved.