Hi there, I am making a game about destruction, and there is a considerable amount of lag even after a simple operation, as it generates lots and lots of little parts.
I can’t really cut down on parts, as I’ve already done that, and anymore would ruin the fun.
I have tried to make a “hack” of anchoring parts when the player is far away, but I can’t seem to have the right algorithim. Here is the code if you want it:
while true do
wait(1)
local players = game.Players:GetPlayers()
local subdividedparts = game.Workspace["Subdivided parts"]:GetChildren()
for i = 1, #players do
if players[i].Character ~= nil then
if players[i].Character:FindFirstChild("UpperTorso") ~= nil then
if subdividedparts ~= nil then
for x = 1, #subdividedparts do
if subdividedparts[x].Position ~= nil then
local cananchor = false
if subdividedparts[x]:FindFirstChild("breakutctime") ~= nil then
if os.time() - subdividedparts[x].breakutctime.Value > 15 then
print("time passed")
cananchor = false
end
end
local normalisedpos = (subdividedparts[x].Position - players[i].Character.UpperTorso.Position)
local totallinearvolicity = math.abs(subdividedparts[x].AssemblyLinearVelocity.X) + math.abs(subdividedparts[x].AssemblyLinearVelocity.Y) + math.abs(subdividedparts[x].AssemblyLinearVelocity.Z)
if (totallinearvolicity < 1 or ((math.abs(normalisedpos.X) + math.abs(normalisedpos.Y) + math.abs(normalisedpos.Z)) > 800)) and cananchor then
subdividedparts[x].AssemblyLinearVelocity = Vector3.new(0, 0, 0)
subdividedparts[x].Anchored = true
else
subdividedparts[x].Anchored = false
end
end
end
end
end
end
end
end
I have followed all of the “optimising your game” roblox pages, such as adaptive physics, but still not luck.
You can see the game here:
https://www.roblox.com/games/9720892069/Destroy-stuff
(it is uncopylocked)
Thanks!