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
GetPartBoundsInSphere
Returns an array of parts within a sphere defined by center and radius. Useful for proximity checks and area-of-effect queries. Uses bounding boxes, so complex shapes may be approximated.
Parameters
CFrame
InCenter
number
InRadius
OverlapParams
InOverlapParams
Return
array
Code Samples
GetPartsInPart
Returns an array of parts that overlap with the specified BasePart. Filtering can be customized via OverlapParams to include/exclude certain objects.
Parameters
BasePart
InBasePart
OverlapParams
InOverlapParams
Return
array
Code Samples
DrawRay
This method displays a ray of a specified color on the screen based on a given origin and direction for visual representation.
This is mainly used for debugging and is helpful for visually identifying the direction and destination of a Raycast.
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 of the ray.
number
InThickness
The width of the ray.
number
InLifeTime
The duration (in seconds) that the ray persists in the world.
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