You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
Hello, i am working on grid based water-physics. But I’ve found out that the game begins lagging BADLY when water begins to flow downwards.
- What is the issue? Include screenshots / videos if possible!
Water-Physics lags game badly when flowing downwards. I’m basically forced to use task manager to close studio.
- What solutions have you tried so far? Did you look for solutions on the Creator Hub?
I’ve looked through the forums for any issues but i cant find my solution.
I think the issue is the raycasts hitting nothing? I’m really confused, but it doesn’t lag out when CanQuery is enabled or the liquid is in a raycast exclusion table. (so it doesn’t hit the water)
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Here’s my script:
local RunService = game:GetService("RunService")
local Block = script.Parent
local Folder = workspace.Liquids -- Holds all the liquid blocks
--CONFIG--
local TickRate = 1 -- time between each raycast
local function fireRay(part)
local dist = 3
local origin = part.Position
local direction = part.CFrame.UpVector * part.Size.Y
local direction2 = part.CFrame.RightVector * part.Size.X
local direction3 = part.CFrame.LookVector * part.Size.Z
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {Folder} -- rays ignore liquid blocks
rayParams.FilterType = Enum.RaycastFilterType.Exclude
local result = workspace:Raycast(origin, -direction, rayParams, dist)
local result2 = workspace:Raycast(origin, direction2, rayParams, dist)
local result3 = workspace:Raycast(origin, direction3, rayParams, dist)
local result4 = workspace:Raycast(origin, -direction2, rayParams, dist)
local result5 = workspace:Raycast(origin, -direction3, rayParams, dist)
if result == nil then -- down
local newWater = Block:Clone()
newWater.Position = part.Position - direction
newWater.Parent = workspace.Liquids
else
if result2 == nil then -- right
local newWater = Block:Clone()
newWater.Position = part.Position + direction2
newWater.Parent = workspace.Liquids
end
if result3 == nil then -- front
local newWater = Block:Clone()
newWater.Position = part.Position + direction3
newWater.Parent = workspace.Liquids
end
if result4 == nil then -- left
local newWater = Block:Clone()
newWater.Position = part.Position - direction2
newWater.Parent = workspace.Liquids
end
if result5 == nil then -- back
local newWater = Block:Clone()
newWater.Position = part.Position - direction3
newWater.Parent = workspace.Liquids
end
end
end
RunService.Heartbeat:Connect(function()
task.wait(TickRate)
fireRay(Block)
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
thanks for reading, hope you know how to help with my problem! ![]()