Started developing again after many months, and what else to do but fix my old, janky code.
I began researching into Parallel Luau and I decided that it’d be best to use it, as my script has to control the collisions & movements of up to 500 parts!
The movement works fine, but the collision and detection of parts outside of the box to be deleted aren’t working. Have I messed up with the maths?
Here’s the source:
local LightFolder = game.Workspace.SimulationParts.LightParticles
local RunService = game:GetService("RunService")
local NameIgnoreList = {['Laser']=true}
local ParentIgnoreList = {"BaseParts","TheBox"}
local cwait = require(game.ReplicatedStorage._Modules.Wait)
local gpip = workspace.GetPartsInPart
local simbox = workspace.BaseParts.TheBox.Ref
local raycast = workspace.Raycast
local ws = workspace
local revVec = Vector3.new(-1,-1,-1)
RunService.PostSimulation:ConnectParallel(function()
for ord, light:Part in pairs(LightFolder:GetChildren()) do
local rayRes = raycast(ws,light.Position,light.Orientation)
if rayRes.Distance < .1 and rayRes.Instance.Parent ~= LightFolder and not NameIgnoreList[rayRes.Instance.Name] then
light.Orientation*= revVec*rayRes.Normal
end
light.CFrame.LookVector = light.Position + light.CFrame.LookVector*1
if not table.find(gpip(ws,light),simbox) then light:Destroy() end
end
end)
And yes, the script is parented by an actor.
1 Like
You are using orientation for the raycast direction. This should probably be its lookvector. Also keep in mind the length of the direction determines how far the ray goes. You have no raycast parameters nor a custom method to refire the ray if it hit a part you want to filter out. Also you should have a check if there is no ray result because it did not hit anything. LookVector is read only and you are trying to set it. Check the output for errors.
Sorry for late reply, forgot to check into the DevForum.
I’ve made this code, no errors show up yet the light particles aren’t moving nor detecting collisions.
local LightFolder = game.Workspace.SimulationParts.LightParticles
local RunService = game:GetService("RunService")
local NameIgnoreList = {['Laser']=true}
local ParentIgnoreList = {"BaseParts"}
local cwait = require(game.ReplicatedStorage._Modules.Wait)
local gpip = workspace.GetPartsInPart
local simbox = workspace.BaseParts.TheBox.Ref
local raycast = workspace.Raycast
local ws = workspace
local revVec = Vector3.new(-1,-1,-1)
local beat
local connections: {[number]:RBXScriptConnection}= {}
LightFolder.ChildAdded:Connect(function(light)
local plate = #LightFolder:GetChildren()
connections[plate] = RunService.PostSimulation:Connect(function()
light.Destroying:Connect(function()
connections[plate]:Disconnect()
end)
light.name = plate
light.CFrame += light.Position + light.CFrame.LookVector*.1
local rayRes = raycast(ws,light.Position,light.CFrame.LookVector)
local function ProcessRay()
if rayRes then
if rayRes.Instance.Parent ~= LightFolder and not NameIgnoreList[rayRes.Instance.Name] then
if rayRes.Distance > .1 then
light.Orientation*= revVec*rayRes.Normal
end
else
rayRes = raycast(ws,light.Position,light.CFrame.LookVector)
ProcessRay()
end
end
end
ProcessRay()
if not table.find(gpip(ws,simbox),light) then light:Destroy() end
end)
end)