This module is pretty cool, though most likely Roblox will add particle collisions, since they’ve been doing some improvements to the particle system, and other systems recently.
To be honest, the source code looks pretty bad. The formatting is weird, there are massive gaps of just whitespace, and some places need newlines to make the code look more readable. For personal projects, readable and good looking code is not important, but for open source community resources, having presentable code can make it easier for other people modify it, although good looking code is purely subjective, some changes have to be made.
I’ve made a few changes to the source code to better align with how my code looks, which is just my opinion, write code however you want, just make it readable to everyone.
--// BIack1st
local ParticleColl = { }
local Blacklisted = { }
local PhysicsS = game:GetService("PhysicsService")
function ParticleColl.new(starterPart: Part, particles: ParticleEmitter)
local function checkGroups(group1: string, group2: string)
return PhysicsS:CollisionGroupsAreCollidable(group1, group2)
end
local groupId = starterPart.CollisionGroupId
local groupName = PhysicsS:GetCollisionGroupName(groupId)
local function getDir(part: BasePart, particles: ParticleEmitter)
local ParticleDirection = particles.EmissionDirection
if ParticleDirection == Enum.NormalId.Top then
return part.CFrame.UpVector
elseif ParticleDirection == Enum.NormalId.Back then
return -part.CFrame.LookVector
elseif ParticleDirection == Enum.NormalId.Front then
return part.CFrame.LookVector
elseif ParticleDirection == Enum.NormalId.Bottom then
return -part.CFrame.UpVector
elseif ParticleDirection == Enum.NormalId.Left then
return -part.CFrame.RightVector
elseif ParticleDirection == Enum.NormalId.Right then
return part.CFrame.RightVector
end
end
local dir = getDir(starterPart, particles)
local result = workspace:Raycast(starterPart.Position, dir * 5000)
if result then
local rayInst = result.Instance
local pos = result.Position
particles.Lifetime = NumberRange.new((starterPart.Position - pos).Magnitude * (5.3 / particles.Speed.Max / 2) / 2.75)
else
particles.Lifetime = NumberRange.new(math.huge)
end
end
return ParticleColl
My version was made for fun, you don’t need to use it.
Here are a few things with your code that should be improved:
- Big gaps of whitespace, e.g. 49 - 56.
- Parts of the code is super clustered together, with nearly no whitespace added to make it look nicer, e.g. 1 - 13
- The array with all the methods is named “module”, not something that tells the reader what it is.
- (Subjective-ish) Capitalized variable / parameter names. Most programmers (including myself) use capitalized names for important data, like constants, module arrays, etc. etc.