local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local workspace = game:GetService("Workspace")
local MaxPool = 670
local Pool, PuddlePool, ActiveDrops = {}, {}, {}
local DropSize = Vector3.new(0.5, 0.75, 0.5)
local DropSpeed = 100
local DropPollDelay = .02
local DropRayDistance = 2
local PuddleSize = Vector3.new(0.1, 2, 2)
local PuddleColor = Color3.fromRGB(154, 28, 30)
local Emitter = workspace:WaitForChild("DropletEmitter")
local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
RayParams.FilterDescendantsInstances = {workspace.Droplets, Emitter}
for i = 1, MaxPool do
local p = Instance.new("Part")
p.Size = DropSize
p.Transparency = 1
p.CanCollide = true
p.Anchored = false
p.Parent = nil
Pool[i] = p
end
for i = 1, MaxPool do
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.Transparency = 0.6
p.Color = PuddleColor
p.Shape = Enum.PartType.Cylinder
p.Material = Enum.Material.SmoothPlastic
p.Parent = nil
PuddlePool[i] = p
end
local function FaceVelocity(part)
local vel = part.Velocity
if vel.Magnitude < 0.01 then return end
part.CFrame = CFrame.lookAt(part.Position, part.Position + vel.Unit, Vector3.yAxis)
end
local function SpawnPuddle(pos)
local hit = workspace:Raycast(pos + Vector3.new(0, 1, 0), Vector3.new(0, -5, 0), RayParams)
if hit then pos = hit.Position end
local Puddle = table.remove(PuddlePool, 1)
if not Puddle then return end
Puddle.Size = Vector3.zero
Puddle.Parent = workspace.Droplets
Puddle.CFrame = CFrame.Angles(0, math.rad(90), math.rad(90)) + pos
local grow = TweenService:Create(Puddle, TweenInfo.new(0.2, Enum.EasingStyle.Back), {Size = PuddleSize, Transparency = 0})
grow:Play()
grow.Completed:Wait()
wait(0.2)
local shrink = TweenService:Create(Puddle, TweenInfo.new(0.2), {Size = Vector3.zero, Transparency = 1})
shrink:Play()
shrink.Completed:Wait()
Puddle.Parent = nil
table.insert(PuddlePool, Puddle)
end
local function FakeDestroyDrop(Drop, i)
Drop.Parent = nil
Drop.Transparency = 1
table.remove(ActiveDrops, i)
table.insert(Pool, Drop)
end
local function SpawnDrop(origin, velocity)
local Drop = table.remove(Pool, 1)
if Drop then
Drop.Parent = workspace.Droplets
Drop.Position = origin
Drop.Velocity = velocity
Drop.Transparency = 0.4
Drop.Material = Enum.Material.SmoothPlastic
Drop.Color = Color3.fromRGB(241, 78, 81)
if not Drop:GetAttribute("LastDir") then
Drop:SetAttribute("LastDir", velocity.Unit)
end
table.insert(ActiveDrops, Drop)
end
end
local LastPoll
RunService.Heartbeat:Connect(function()
if not LastPoll then LastPoll = tick() end
if tick() - LastPoll < DropPollDelay then return end
LastPoll = tick()
for i = #ActiveDrops, 1, -1 do
local Drop = ActiveDrops[i]
local pos, vel = Drop.Position, Drop.Velocity
local downRay = workspace:Raycast(pos, Vector3.new(0, -DropRayDistance, 0), RayParams)
if downRay then
local N = downRay.Normal
local globalDown = Vector3.new(0, -1, 0)
local tangent = (vel - N * vel:Dot(N)).Unit
local downward = (globalDown - N * globalDown:Dot(N)).Unit
if downward.Y < -0.001 then
Drop.Velocity = downward * vel.Magnitude
else
Drop.Velocity = tangent * vel.Magnitude
end
if N.Y > 0.99 then
task.spawn(SpawnPuddle, pos)
FakeDestroyDrop(Drop, i)
continue
end
end
local ray = workspace:Raycast(pos, vel.Unit * 0.5, RayParams)
if ray then
local N = ray.Normal
Drop.Velocity = (vel - N * vel:Dot(N)).Unit * vel.Magnitude
end
local lastDir = Drop:GetAttribute("LastDir")
if not lastDir then
Drop:SetAttribute("LastDir", vel.Unit)
elseif lastDir:Dot(vel.Unit) < 0.98 then
FaceVelocity(Drop)
Drop:SetAttribute("LastDir", vel.Unit)
end
end
end)
local function Drop()
local cf, size = Emitter.CFrame, Emitter.Size
local offsetX, offsetY = (math.random() - 0.5) * size.X, (math.random() - 0.5) * size.Y
local frontPos = cf.Position + cf.LookVector * (size.Z / 2) + cf.RightVector * offsetX + cf.UpVector * offsetY
local frontDir = cf.LookVector
SpawnDrop(frontPos, frontDir * DropSpeed)
end
RunService.Heartbeat:Connect(function()
for _ = 1, 2 do Drop() end
end)
i added a polling delay
by changing the polling delay and the raycast length you can kind of fine tune it.
it also makes it less laggy.