• Studio

  • Bots

  • Web API

  • Designer Resources

  • Host Resources

  • API

    Datatypes

    Edit

    Vector3

    Vector3 represents three-dimensional space as coordinates, physical quantities, or directions, containing three numerical components (x, y, and z). It is used in Unity for physics, animations, and transformations.

    Properties

    ServerAndClient

    Instantiates a new Vector3 object by specifying x, y, and z coordinates, representing a point in the Unity game world's 3D space.

    Returns a version of this Vector3 with a magnitude of one, maintaining its direction. Useful for unit direction vectors.

    local normalizedVector = position.normalized
    print(normalizedVector) -- Vector3(0.26726123690605, 0.5345224738121, 0.80178368043899)
    

    magnitude

    number

    Provides the length of a Vector3, calculated as the Euclidean distance to (0,0,0), useful for distance calculations in 3D space.

    local magnitude = position.magnitude
    print(magnitude) -- 3.7416573867739
    

    Returns the square of the magnitude, an alternative for performance-sensitive calculations where exact distance is not necessary.

    local sqrMagnitude = position.sqrMagnitude
    print(sqrMagnitude) -- 14
    

    x

    number

    ServerAndClient

    Represents the x-coordinate of the Vector3, allowing direct manipulation or reading of its x-component.

    position.x = 5
    print(position.x) -- 5
    

    y

    number

    ServerAndClient

    Corresponds to the y-coordinate of the Vector3, for manipulating or reading the y-component.

    position.y = 10
    print(position.y) -- 10
    

    z

    number

    ServerAndClient

    Represents the z-coordinate of the Vector3, used for direct manipulation or reading of the z-component.

    position.z = 15
    print(position.z) -- 15
    

    Generates a Vector3 with zero values for all coordinates, representing the origin in 3D space or indicating no motion or rotation.

    local zeroVector = Vector3.zero
    print(zeroVector) -- Vector3(0, 0, 0)
    

    Generates a Vector3 object with all components set to 1, useful for pointing diagonally in 3D space.

    local oneVector = Vector3.one
    print(oneVector) -- Vector3(1, 1, 1)
    

    Returns a Vector3 pointing towards the positive Z-axis, useful for designating a forward direction.

    Provides a Vector3 pointing towards the negative Z-axis, often used to designate a backward direction.

    local backVector = Vector3.back
    print(backVector) -- Vector3(0, 0, -1)
    

    Offers a Vector3 pointing upwards along the positive Y-axis, handy for upward movements or orientations.

    local upVector = Vector3.up
    print(upVector) -- Vector3(0, 1, 0)
    

    Represents a Vector3 pointing downwards along the negative Y-axis, typically used for downward directions.

    local downVector = Vector3.down
    print(downVector) -- Vector3(0, -1, 0)
    

    Returns a Vector3 pointing in the negative X-axis direction, used to signify left direction in 3D space.

    local leftVector = Vector3.left
    print(leftVector) -- Vector3(-1, 0, 0)
    

    Provides a Vector3 pointing towards the positive X-axis, recognized as the right direction in 3D space.

    local rightVector = Vector3.right
    print(rightVector) -- Vector3(1, 0, 0)
    

    Yields a Vector3 with all components set to positive infinity, useful for representing very large values.

    local positiveInfinityVector = Vector3.positiveInfinity
    print(positiveInfinityVector) -- Vector3(inf, inf, inf)
    

    Generates a Vector3 with all components set to negative infinity, representing the smallest possible values in 3D space.

    local negativeInfinityVector = Vector3.negativeInfinity
    print(negativeInfinityVector) -- Vector3(-inf, -inf, -inf)
    

    Provides a very small positive number, used for comparisons to determine if Vector3 components are approximately zero, considering floating-point inaccuracies.

    local epsilon = Vector3.kEpsilon
    print(epsilon) -- 1.4012984643248e-45
    

    A small positive number used in square root calculations, representing a negligible threshold value for comparing Vector3 magnitudes.

    local epsilonSqrt = Vector3.kEpsilonNormalSqrt
    print(epsilonSqrt) -- 1.1754943508223e-38
    

    Methods

    Changes the x, y, and z values of an existing Vector3 object, useful for simultaneous updates to all three components.

    position:Set(5, 10, 15)
    print(position) -- Vector3(5, 10, 15)
    

    Parameters

    newX

    number

    The new value for the x-coordinate.

    newY

    number

    The new value for the y-coordinate.

    newZ

    number

    The new value for the z-coordinate.

    Returns

    void

    Multiplies each component of the Vector3 by the corresponding components of another Vector3, used to alter the scale without changing its direction.

    position:Scale(Vector3.new(2, 2, 2))
    print(position) -- Vector3(10, 20, 30)
    

    Parameters

    scale
    Vector3

    A Vector3 by which the instance vector is scaled.

    Returns

    void

    Adjusts the Vector3 to a length of one while maintaining its direction, useful for when only the direction is of interest.

    position:Normalize()
    print(position) -- Vector3(0.26726123690605, 0.5345224738121, 0.80178368043899)
    

    Returns

    void

    Creates a smooth transition between two Vector3 points on a sphere's surface, ideal for smooth transitions in rotations or positions.

    local start = Vector3.new(1, 0, 0)
    local finish = Vector3.new(0, 1, 0)
    
    local slerpVector = Vector3.Slerp(start, finish, 0.5)
    print(slerpVector) -- Vector3(0.70710676908493, 0.70710676908493, 0)
    

    Parameters

    The starting Vector3 point.

    The ending Vector3 point.

    t

    number

    The interpolation factor between 0 and 1.

    Returns

    Vector3

    A Vector3 point along the shortest path between 'a' and 'b'.

    Similar to 'Slerp' but allows the 't' value to exceed the 0 to 1 range, enabling extrapolation beyond the original points.

    local position = Vector3.new(1, 0, 0)
    
    local a = Vector3.new(0, 1, 0)
    local b = Vector3.new(0, 0, 1)
    
    local t = 1.5
    local result = Vector3.SlerpUnclamped(a, b, t)
    
    print(result) -- Vector3(0, -0.5, 0.5)
    

    Parameters

    The starting Vector3 point.

    The ending Vector3 point.

    t

    number

    An extrapolation factor beyond 0 and 1.

    Returns

    Vector3

    A new Vector3 point potentially extrapolated beyond 'b'.

    Gradually rotates a Vector3 'current' to align with a 'target' Vector3, with specified maximum rotation and magnitude change limits.

    local current = Vector3.new(1, 0, 0)
    local target = Vector3.new(0, 1, 0)
    
    local maxRadiansDelta = 0.1
    local maxMagnitudeDelta = 0.1
    
    local result = Vector3.RotateTowards(current, target, maxRadiansDelta, maxMagnitudeDelta)
    
    print(result) -- Vector3(0.70710676908493, 0.70710676908493, 0)
    

    Parameters

    current
    Vector3

    The current Vector3 from which rotation starts.

    target
    Vector3

    The target Vector3 towards which rotation is aimed.

    maxRadiansDelta

    number

    Maximum rotation allowed in radians.

    maxMagnitudeDelta

    number

    Maximum change in magnitude allowed.

    Returns

    Vector3

    The Vector3 after rotating towards the target.

    Performs linear interpolation between two Vector3s, transitioning from 'a' to 'b' based on the 't' ratio.

    local start = Vector3.new(1, 0, 0)
    local finish = Vector3.new(0, 1, 0)
    
    local lerpVector = Vector3.Lerp(start, finish, 0.5)
    print(lerpVector) -- Vector3(0.5, 0.5, 0)
    

    Parameters

    The starting Vector3 point.

    The ending Vector3 point.

    t

    number

    The interpolation factor, in the range 0 to 1.

    Returns

    Vector3

    A new Vector3 point interpolated between 'a' and 'b'.

    Similar to 'Lerp', this method performs linear interpolation between two points, but allows 't' to exceed the 0 to 1 range, enabling extrapolation.

    local start = Vector3.new(1, 0, 0)
    local finish = Vector3.new(0, 1, 0)
    
    local t = 1.5
    local result = Vector3.LerpUnclamped(start, finish, t)
    
    print(result) -- Vector3(-0.5, 0.5, 0)
    

    Parameters

    The starting Vector3 point.

    The ending Vector3 point.

    t

    number

    The interpolation factor, not limited to between 0 and 1.

    Returns

    Vector3

    A new Vector3 point interpolated (or extrapolated) between 'a' and 'b'.

    Moves a Vector3 ('current') incrementally towards a target Vector3 ('target') at a specified 'maxDistanceDelta'.

    local current = Vector3.new(1, 0, 0)
    local target = Vector3.new(0, 1, 0)
    
    local maxDistanceDelta = 0.1
    local result = Vector3.MoveTowards(current, target, maxDistanceDelta)
    
    print(result) -- Vector3(0.9, 0.1, 0)
    

    Parameters

    current
    Vector3

    The current Vector3 to move.

    target
    Vector3

    The target Vector3 to move towards.

    maxDistanceDelta

    number

    The maximum distance the Vector3 can move in one call.

    Returns

    Vector3

    A Vector3 moved towards the target.

    Creates a new Vector3 from the product of corresponding components of two given Vector3s, affecting the size without changing direction.

    local a = Vector3.new(1, 2, 3)
    local b = Vector3.new(4, 5, 6)
    
    local result = Vector3.Scale(a, b)
    print(result) -- Vector3(4, 10, 18)
    

    Parameters

    The first Vector3 used for scaling.

    The second Vector3 used for scaling.

    Returns

    Vector3

    The resulting Vector3 after scaling.

    Calculates the cross product of two Vector3 instances, resulting in a Vector3 perpendicular to both, used for finding normals or rotation axes.

    local lhs = Vector3.new(1, 0, 0)
    local rhs = Vector3.new(0, 1, 0)
    
    local crossProduct = Vector3.Cross(lhs, rhs)
    print(crossProduct) -- Vector3(0, 0, 1)
    

    Parameters

    The first Vector3 to cross.

    The second Vector3 to cross.

    Returns

    Vector3

    The cross product of the two Vector3s.

    Reflects a Vector3 off a surface with a specified normal, useful for simulating reflections or ricochets.

    local inDirection = Vector3.new(1, 0, 0)
    local inNormal = Vector3.new(0, 1, 0)
    
    local reflectedVector = Vector3.Reflect(inDirection, inNormal)
    print(reflectedVector) -- Vector3(1, 0, 0)
    

    Parameters

    inDirection
    Vector3

    The incoming Vector3 to reflect.

    inNormal
    Vector3

    The normal Vector3 off which to reflect.

    Returns

    Vector3

    The reflected Vector3.

    Normalizes a Vector3, returning a new Vector3 with the same direction but a magnitude of 1, useful for direction without magnitude concern.

    local vector = Vector3.new(1, 2, 3)
    local normalizedVector = Vector3.Normalize(vector)
    
    print(normalizedVector) -- Vector3(0.26726123690605, 0.5345224738121, 0.80178368043899)
    

    Parameters

    value
    Vector3

    The Vector3 to normalize.

    Returns

    Vector3

    A normalized version of the input Vector3.

    Calculates the Dot Product of two Vector3s, useful for determining directional alignment or the angle between vectors.

    local lhs = Vector3.new(1, 0, 0)
    local rhs = Vector3.new(0, 1, 0)
    
    local dotProduct = Vector3.Dot(lhs, rhs)
    print(dotProduct) -- 0
    

    Parameters

    The first Vector3 for the dot product.

    The second Vector3 for the dot product.

    Returns

    number

    The dot product of the two Vector3s.

    Projects a Vector3 onto another, useful for finding the component of one vector in the direction of another.

    local vector = Vector3.new(1, 2, 3)
    local onNormal = Vector3.new(1, 0, 0)
    
    local projectedVector = Vector3.Project(vector, onNormal)
    print(projectedVector) -- Vector3(1, 0, 0)
    

    Parameters

    vector
    Vector3

    The Vector3 being projected.

    onNormal
    Vector3

    The Vector3 on which the projection occurs.

    Returns

    Vector3

    The projection of the first Vector3 onto the second.

    Projects a Vector3 onto a plane defined by a normal orthogonal Vector3, useful for aligning objects to surfaces.

    local vector = Vector3.new(1, 2, 3)
    local planeNormal = Vector3.new(0, 1, 0)
    
    local projectedVector = Vector3.ProjectOnPlane(vector, planeNormal)
    print(projectedVector) -- Vector3(1, 0, 3)
    

    Parameters

    vector
    Vector3

    The Vector3 being projected onto a plane.

    planeNormal
    Vector3

    The normal Vector3 of the plane onto which the projection occurs.

    Returns

    Vector3

    The Vector3 after being projected onto a plane.

    Calculates the angle in degrees between two Vector3s, useful for determining the required rotation to align one Vector3 with another.

    local from = Vector3.new(1, 0, 0)
    local to = Vector3.new(0, 1, 0)
    
    local angle = Vector3.Angle(from, to)
    print(angle) -- 90
    

    Parameters

    The origin Vector3 for angle measurement.

    The destination Vector3 for angle measurement.

    Returns

    number

    The angle in degrees between the two Vector3s.

    Calculates the angle between two Vector3s with a sign indicating rotation direction around a given axis.

    local from = Vector3.new(1, 0, 0)
    local to = Vector3.new(0, 1, 0)
    
    local axis = Vector3.new(0, 0, 1)
    local angle = Vector3.SignedAngle(from, to, axis)
    print(angle) -- 90
    

    Parameters

    The Vector3 from where the angle measurement starts.

    The Vector3 to which the angle measurement is made.

    The axis around which the rotation angle is measured.

    Returns

    number

    The signed angle in degrees between the two Vector3s.

    Calculates the distance between two Vector3 points, typically used to determine how far apart two objects are in 3D space.

    local a = Vector3.new(1, 0, 0)
    local b = Vector3.new(0, 1, 0)
    
    local distance = Vector3.Distance(a, b)
    print(distance) -- 1.4142135381699
    

    Parameters

    The first Vector3 point.

    The second Vector3 point.

    Returns

    number

    The distance between the two Vector3 points.

    Limits the magnitude of a Vector3 to a specified maximum, useful for constraining movement or other vector magnitudes.

    local vector = Vector3.new(1, 2, 3)
    local maxLength = 2
    
    local clampedVector = Vector3.ClampMagnitude(vector, maxLength)
    print(clampedVector) -- Vector3(0.55470019578934, 1.1094003915787, 1.6641006469727)
    

    Parameters

    vector
    Vector3

    The Vector3 to clamp.

    maxLength

    number

    The maximum length to which the Vector3's magnitude is clamped.

    Returns

    Vector3

    The Vector3 with its magnitude clamped.

    Returns the magnitude (length) of a Vector3, useful for distance calculations from the origin.

    local vector = Vector3.new(1, 2, 3)
    local magnitude = Vector3.Magnitude(vector)
    
    print(magnitude) -- 3.7416573867739
    

    Parameters

    vector
    Vector3

    The Vector3 of which to calculate the magnitude.

    Returns

    number

    The magnitude of the Vector3.

    Calculates the square of the magnitude of a Vector3, often used for performance reasons in relative length comparisons.

    local vector = Vector3.new(1, 2, 3)
    local sqrMagnitude = Vector3.SqrMagnitude(vector)
    
    print(sqrMagnitude) -- 14
    

    Parameters

    vector
    Vector3

    The Vector3 of which to calculate the square of the magnitude.

    Returns

    number

    The square of the magnitude of the Vector3.

    Returns a Vector3 composed of the smallest x, y, and z components from two given Vector3s, useful for bounding calculations.

    local a = Vector3.new(1, 2, 3)
    local b = Vector3.new(3, 2, 1)
    
    local minVector = Vector3.Min(a, b)
    print(minVector) -- Vector3(1, 2, 1)
    

    Parameters

    The first Vector3 for comparison.

    The second Vector3 for comparison.

    Returns

    Vector3

    A Vector3 made up of the smallest components from the two input Vector3s.

    Produces a Vector3 from the largest x, y, and z components of two given Vector3s, useful for defining bounds or extents.

    local a = Vector3.new(1, 2, 3)
    local b = Vector3.new(3, 2, 1)
    
    local maxVector = Vector3.Max(a, b)
    print(maxVector) -- Vector3(3, 2, 3)
    

    Parameters

    The first of two Vector3s to compare.

    The second of two Vector3s to compare.

    Returns

    Vector3

    A Vector3 composed of the largest components of the two compared Vector3s.

    Updated 3 months ago

    PocketWorlds Icon

    © 2024 Pocket Worlds. All rights reserved.