WorldRoot

WorldRoot : Instance

Overview

This code defines the WorldRoot class, a subclass of Instance, designed for raycasting and instance management within game worlds. It includes methods such as FindPartOnRay and Raycast to perform collision queries and find parts in the scene. The WorldRoot also provides a templated function, FindInstanceByPred, for searching instances based on custom predicates and internal helper functions for handling parameters initialization and hit result processing. This functionality is intended for use within a Lua-based game engine environment.

Description

WorldRoot is a core component in Overdare Studio's Lua API, serving as the root for managing virtual worlds within its Lua environment. It provides essential functionality to interact with game elements and manipulate them through Lua scripts. In terms of structure, it bridges the gap between C++ engine and Lua scripting languages for controlling various aspects of a game world. Key methods in WorldRoot include 'FindPartOnRay' for identifying and retrieving specific game elements based on raycast information and 'Raycast' for performing ray-tracing operations within the game environment. Both functions enable

Properties

Methods

FindPartOnRay

The FindPartOnRay method is used to detect and retrieve the first part along a given ray's trajectory within the world. It allows for raycasting operations and supports options for filtering through parameters like ignoring specific descendants, treating terrain cells as cubes, and ignoring water bodies. This method is useful for implementing precise object interactions and collision detection in a game environment.

Parameters

Ray InRay

Instance InIgnoreDescendantsInstance

bool bInTerrainCellsAreCubes

bool bInIgnoreWater

Return

array

Code Samples

Raycast

The Raycast method performs a ray-tracing operation from a given origin in a specific direction within the game world. It returns detailed information about the first object hit, if any, along the ray's path. This method is essential for physics interactions, line-of-sight calculations, and gameplay mechanics that rely on precise spatial queries.

Parameters

Vector3 InOrigin

Vector3 InDirection

RaycastParams InRaycastParams

Return

ULuaRaycastResult

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.FilterDescendantsInstances = 
{ 
    -- λ ˆμ΄κ°€ λ¬΄μ‹œν•  객체듀
    Workspace.Part
}
RaycastParams.FilterType = Enum.RaycastFilterType.Include -- λ¬΄μ‹œ 리슀트 μ„€μ • (이거 λ„£μ–΄μ€˜μ•Ό λ™μž‘ν•¨)

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

GetPartBoundsInBox computes the parts intersecting or within a specified box area, centered at a given point and with defined size. This method is particularly useful for detecting objects in a specified region, implementing area-of-effect mechanics, and determining spatial relationships between items within a predefined boundary.

Parameters

CFrame InCenter

Vector3 InSize

OverlapParams InOverlapParams

Return

array

Code Samples

Events