Hand-written by Joseph San Nicolas, Roblox Developer
RaycastResult
Constructors
| Name | Description |
| WorldRoot:Raycast(origin: Vector3,direction: Vector3,raycastParams: RaycastParams?):RaycastResult | Returned 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
| Name | Type | Description |
| Instance | BasePart | The BasePart or Terrain cell that the ray intersected. |
| Position | Vector3 | The world-space point at which the intersection occurred, usually a point directly on the surface of the BasePart or Terrain cell. |
| Normal | Vector3 | The normal vector of the intersected face, pointing away from the surface. |
| Material | Enum.Material | The 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. |
| Distance | number | The distance between the ray's origin and the intersection point. |