MultiRaycast - Easy & optimized parallel raycast

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

Learn more about Parallel Roblox

10 Likes


I’m getting a warning in my code using .Signal with any of the functions.
I’m using strict type.

image
If you could make these events use your Warp module that would be some insane performance.
I recommend doing this!

I tried using this module but it didn’t work for me in a local script, and when :run()ing I saw it goes into a run service loop which is not what I need. If you could add something like :once() and a debug line that would be nice and I would continue using it,

there do u place it on? localscripts wont run on workspace descendants.

im a good scripter i know what im doing, i of course placed the module in replicated storage and localscript in starter pack