My physics simulation “powder game” is a game where every particle interacts with every other particle independently, and each particle is created through one of five classes held in ModuleScripts.
My “gravity-well” particle is part of class “Block” (although this is unimportant). The aim of gravity-well particle is to pull the other particles around it toward it and hold them there, almost floating. This all works well with the code I have wrote; however, I am worried that the game will suffer massive performance issues if too many exist at once. All threads are properly destroyed once a particle expires (25 seconds). It would only be possible for 3 per player to exist at any moment in time.
Maybe I am handling this good enough, but I have concerns about performance:
elseif self.Type == "gravity_well" then local m, x = self.SelfMesh.Position - (5 * self.SelfMesh.Size), self.SelfMesh.Position + (5 * self.SelfMesh.Size) local R3 = Region3.new(m, x) local foundObjects local mult = 90 local hold = .075 spawn(function() while true do sWait(hold) mult = mult + hold foundObjects = workspace:FindPartsInRegion3(R3, self.SelfMesh, 75) for i = 1, #foundObjects do if gravity_wellWhitelist[foundObjects[i].Name] and i <= 75 then foundObjects[i].CanCollide = false foundObjects[i]:ApplyImpulse(((self.SelfMesh.Position - foundObjects[i].Position).unit * mult) * Vector3.new(1,0,1)) foundObjects[i].CanCollide = true end end end end) -- More code exists before if statement ends entirely. -- All created threads are disconnected/destroyed after 25 seconds. end
All help is appreciated.