Introduction
What is this? MultiRaycast is simple, strictly-typed and use multiple actors to run raycast in parallel. MultiRaycast make easier use to raycast in parallel and optimize your raycast performance with roblox parallel engine.
Installation
First you need to have the module, you can find it here (by GitHub or Download), then now you can import it into your directory.
Usage
-- MultiRaycast module works on server/client side.
-- Example Usage
--!native
--!optimize 2
local MultiRaycast = require(...) -- link to MultiRaycast module path
local ACTOR_TO_USE = 4 -- we will be using 4 actors here
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = { workspace.Part }
rayParams.FilterType = Enum.RaycastFilterType.Exclude
-- create new Raycast with MultiRaycast module
local newRaycast = RaycastModule.new("Test", script, rayParams, ACTOR_TO_USE)
-- connect to raycast signal to receive rayResult
newRaycast.Signal:Connect(function(rayResult: RaycastResult)
print(rayResult) -- print ray result
end)
-- run the raycast simulation
newRaycast:run()
-- add 10s delay
task.delay(10, function()
newRaycast:stop() -- stop the raycast or maybe you want to destroy it instead? use :destroy()
end)
APIs
-
new
( header: string, directory: Instance, raycastParam: RaycastParams?, actors: number? )
-
run
( forceRun: boolean? )
- stop
- destroy
-
updateFilter
( raycastParam: RaycastParams )
-
setOrigin
( origin: Vector3 )
-
setDirection
( direction: Vector3 )
Performance
Simply, using parallel will optimize your efficiency and performance by multiple times, so i ran a test with this module and compare with non-parallel.
- Non-parallel: ~60/s RayResult’s
- With-parallel (4 actors): 240/s RayResult’s
- With-parallel (8 actors): 480/s RayResult’s
- With-parallel (12 actors): 720/s RayResult’s
- With-parallel (30 actors): ~1800/s RayResult’s