Help with moving parts for fluid simulation

Hello,
I’ve recently been working on a water simulation module called RoPhys and have realized that moving parts is causing most of the lag in my systems.

You can see it a lot here:

(looks a lot smoother in-game when not in the form of a low-quality compressed vid)

Another One:

local bulkPartList, bulkCFrameList = {}, {}

local function updateParticles(dt, u, v)
	local survivors = {}

	-- clear the batch tables
	table.clear(bulkPartList)
	table.clear(bulkCFrameList)

	-- build aligned arrays
	for _, data in ipairs(activeParticles) do
		data.age += dt
		local p   = data.particle
		local pos = p.Position

		-- convert back to grid coords by subtracting center
		local localPos = pos - simulationCenter
		local i = math.floor(localPos.X/gridSize) + 1
		local j = math.floor(localPos.Z/gridSize) + 1

		local ux, vz = 0, 0
		if u[i] and u[i][j] then
			ux, vz = u[i][j], v[i][j]
		end

		local newPos    = pos + Vector3.new(ux, 0, vz) * (dt*gridSize*velocityMultiplier)
		local newCFrame = CFrame.new(newPos)

		bulkPartList[#bulkPartList+1]     = p
		bulkCFrameList[#bulkCFrameList+1] = newCFrame

		if data.age < maxParticleLifetime then
			survivors[#survivors+1] = data
		else
			p:Destroy()
		end
	end

	-- move parts
	if #bulkPartList > 0 then
		workspace:BulkMoveTo(
			bulkPartList,
			bulkCFrameList,
			Enum.BulkMoveMode.FireCFrameChanged
		)
	end

	activeParticles = survivors
end

Any help would be appreciated.
Thanks

1 Like

You gave no context for how you actually move the parts, so this might not be useful. But try using :BulkMoveTo(), assuming you’re moving each part manually instead of using, say, a physics constraint.

Since we don’t have open source and you provided almost no context, my only recommendations as said above: use BulkMoveTo, or use raw metamethod calls

I updated the post with the particle movement code. I am using bulkMoveTo idk if I’m using it properly tho