RaycastResult

Overview

RaycastResult is a data type that contains result information about what target a raycast actually collided with. It is returned when a WorldRoot:Raycast call succeeds and provides various data needed for raycast result analysis, such as collision point, collided object, and surface information.

Constructors

Properties

Distance

number

Represents the straight-line distance from where the Raycast started to where the collision occurred.

Code Samples

local Workspace = game:GetService("Workspace")

local Origin = Vector3.new(0, 50, -0)
local Direction = Vector3.new(0, 0, -3000)

local Result = Workspace:Raycast(Origin, Direction)
if Result then
   print("Hit distance:", Result.Distance)
end

Instance

Instance

Represents the target object the Raycast collided with.

Code Samples

Position

Vector3

Represents the position where the Raycast collided with the target as coordinates in world space.

Code Samples

Normal

Vector3

A vector representing the direction the surface that the Raycast collided with is facing. It is based on the direction perpendicular to the plane at the collision point, and used in subsequent operations such as reflection processing, angle calculation, and surface direction detection.

Code Samples

Methods

See also

WorldRootchevron-right

Last updated