RaycastResult

Constructors

NameDescription
WorldRoot:Raycast(origin: Vector3,direction: Vector3,raycastParams: RaycastParams?):RaycastResultReturned by calling :Raycast() on a WorldRoot (most commonly the workspace) - RaycastResult has no direct constructor of its own. If the ray doesn't hit anything, :Raycast() returns nil instead of a RaycastResult.

Code Snippet

local params = RaycastParams.new()
params.ExcludeInstances = {player.Character}

local origin = Vector3.new(0, 10, 0)
local direction = Vector3.new(0, -50, 0)

local result = workspace:Raycast(origin, direction, params)
if result then
    print("Hit part:", result.Instance.Name)
    print("Hit position:", result.Position)
    print("Surface normal:", result.Normal)
    print("Material:", result.Material.Name)
    print("Distance:", result.Distance)
end

Properties

NameTypeDescription
InstanceBasePartThe BasePart or Terrain cell that the ray intersected.
PositionVector3The world-space point at which the intersection occurred, usually a point directly on the surface of the BasePart or Terrain cell.
NormalVector3The normal vector of the intersected face, pointing away from the surface.
MaterialEnum.MaterialThe material at the intersection point. For ordinary parts this matches the part's Material; for Terrain it depends on the terrain data at that point.
DistancenumberThe distance between the ray's origin and the intersection point.