WorldRoot
WorldRoot : Instance
Overview
A WorldRoot is a class used for detecting or simulating Objects in 3D space.
Properties
Methods
Raycast
It casts an invisible ray from a given origin in a specified direction to detect Objects along the path, returning the result as a RaycastResult Object.
You can optionally use a RaycastParams Object to define specific targets or conditions for detection. If omitted, the default settings apply, and all parts become detectable.
Parameters
Vector3
InOrigin
The starting point from which the ray is cast.
Vector3
InDirection
This vector defines the direction of the ray. The length (magnitude) of this vector also determines how far the ray can detect Objects.
RaycastParams
InRaycastParams
This configuration Object is used to define the conditions for which Objects should be detected.
Return
RaycastResult
Code Samples
local Workspace = game:GetService("Workspace")
local Origin = Vector3.new(0, 50, 0)
local Direction = Vector3.new(0, 0, -3000)
local RaycastParams = RaycastParams.new()
RaycastParams.FilterType = Enum.RaycastFilterType.Exclude
RaycastParams.FilterDescendantsInstances =
{
Workspace.Part
}
local Result = Workspace:Raycast(Origin, Direction, RaycastParams)
if Result then
print("Result Position : ", Result.Position)
print("Result Name : ", Result.Instance.Name)
else
print("Result nil")
end
GetPartBoundsInBox
Searches for and returns an array of parts that overlap with a box-shaped region defined by a given center and size.
Detection is based on each part's bounding box rather than its actual shape, so accuracy may be lower for non-cuboid forms like spheres, cylinders, or complex MeshParts.
Use OverlapParams to fine-tune filtering conditions and detection scope.
Parameters
CFrame
InCenter
This is the center coordinate of the area to be detected.
Vector3
InSize
These are the width, height, and depth of the box-shaped detection area.
OverlapParams
InOverlapParams
This configuration Object is used to define the conditions for which Objects should be detected.
Return
array
Code Samples
local Center = Vector3.new(0, 50, 0)
local Size = Vector3.new(1000, 1000, 1000)
local Cframe = CFrame.new(Center)
local PartsInBox = workspace:GetPartBoundsInBox(Cframe, Size)
for _, obj in ipairs(PartsInBox) do
print(obj.Name)
end
DrawRay
Visualizes a ray in the 3D world using a colored line, primarily for debugging purposes. This method draws a visible ray from a specified origin point in a given direction. It is often used to debug raycasting logic by showing where rays are being cast.
Parameters
Vector3
InOrigin
The starting point from which the ray is cast.
Vector3
InDirection
This vector defines the direction of the ray. The length (magnitude) of this vector also determines how far the ray can detect Objects.
Color3
InColor
The color to render the ray.
number
InThickness
The width of the drawn ray line.
number
InLifeTime
Duration (in seconds) the ray will remain visible in the 3D scene.
Return
void
Code Samples
local Workspace = game:GetService("Workspace")
local Origin = Vector3.new(0, 50, 0)
local Direction = Vector3.new(0, 0, -1000)
local Color = Color3.fromRGB(255, 0, 0)
local Thickness = 5
local LifeTime = 1.5
Workspace:DrawRay(Origin, Direction, Color, Thickness, LifeTime)
Events
Last updated