• Studio

  • Bots

  • Web API

  • Designer Resources

  • Host Resources

  • API

    Datatypes

    Edit

    RaycastHit

    Stores information returned by a raycast, a technique used to detect objects in a certain path or direction in video games. It contains data such as the hit collider, hit point, surface normal, distance from the ray's origin, etc.

    Properties

    Contains the collider hit by the ray. It can be used to access the collider's properties and methods.

    local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 1))
    local hit = Physics.Raycast(ray)
    
    local collider = hit.collider
    print(collider.name) -- Name of the collider hit by the ray
    

    Holds the unique identifier for the collider hit by the ray. This identifier is unique to each collider in the game.

    local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 1))
    local hit = Physics.Raycast(ray)
    
    local colliderInstanceID = hit.colliderInstanceID
    print(colliderInstanceID) -- Unique identifier of the collider hit by the ray
    

    The point in world space where the raycast hit the collider. It represents the position of the hit point.

    local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 1))
    local hit = Physics.Raycast(ray)
    
    local point = hit.point
    print(point) -- Position of the hit point
    

    Gives the normal of the surface hit by the ray. The normal is a vector perpendicular to the surface at the hit point.

    local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 1))
    local hit = Physics.Raycast(ray)
    
    local normal = hit.normal
    print(normal) -- Normal of the surface hit by the ray
    

    Provides the barycentric coordinates of the hit point on the mesh. Barycentric coordinates are used to represent a point on a triangle.

    local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 1))
    local hit = Physics.Raycast(ray)
    
    local barycentricCoordinate = hit.barycentricCoordinate
    print(barycentricCoordinate) -- Barycentric coordinates of the hit point
    

    distance

    number

    Refers to the distance from the ray's origin to the hit point. It represents the length of the ray from the origin to the hit point.

    local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 1))
    local hit = Physics.Raycast(ray)
    
    local distance = hit.distance
    print(distance) -- Distance from the ray's origin to the hit point
    

    Holds the index of the triangle hit by the ray. The triangle index is used to identify the triangle hit by the ray.

    local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 1))
    local hit = Physics.Raycast(ray)
    
    local triangleIndex = hit.triangleIndex
    print(triangleIndex) -- Index of the triangle hit by the ray
    

    Provides the coordinates of the texture hit by the ray. The texture coordinates are used to map textures to 3D models.

    local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 1))
    local hit = Physics.Raycast(ray)
    
    local textureCoord = hit.textureCoord
    print(textureCoord) -- Coordinates of the texture hit by the ray
    

    Provides the coordinates of the second texture hit by the ray. The second texture coordinates are used to map textures to 3D models.

    local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 1))
    local hit = Physics.Raycast(ray)
    
    local textureCoord2 = hit.textureCoord2
    print(textureCoord2) -- Coordinates of the second texture hit by the ray
    

    Provides the Transform of the object that was hit. The Transform represents the position, rotation, and scale of the object.

    local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 1))
    local hit = Physics.Raycast(ray)
    
    local transform = hit.transform
    print(transform.name) -- Name of the object hit by the ray
    

    Offers access to the Rigidbody of the hit object, if it has one. The Rigidbody is used to simulate physics on an object.

    local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 1))
    local hit = Physics.Raycast(ray)
    
    local rigidbody = hit.rigidbody
    print(rigidbody.name) -- Name of the Rigidbody of the hit object
    

    Provides the coordinates of the lightmap hit by the ray. The lightmap coordinates are used to map lightmaps to 3D models.

    local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, 0, 1))
    local hit = Physics.Raycast(ray)
    
    local lightmapCoord = hit.lightmapCoord
    print(lightmapCoord) -- Coordinates of the lightmap hit by the ray
    

    Updated about 2 months ago

    PocketWorlds Icon

    © 2024 Pocket Worlds. All rights reserved.