Destroy Module
What is that?
Is a module that help you with destroyable in your game.
(if you don’t want to read this just check the video: - YouTube)
Information
Properties:
Photo
object - Instance : Object to destroy(you can use nil if don’t use object_calculation)
position - Vector3 : Position where we create parts to SubtractAsync()
size - Table : Uses for randomize part size.(Ex. {1, 5} - creates part with size from 1 to 5)
partcount - Int : Number how many destroy parts you want(can be 100 and more but be lag)
Settings:
Debris
Photo
Enabled - Bool : enables/disables debris.
Lifetime - Int : how long time need to delete it.
Count - how many debris creates per Destroy.
(READ: Debris size equal to this formula: ((size[2] + size[1])/settings.debris.count) / 2)
Attribute Check
Photo
Just check attribute ‘destroyable’. If true then Destroy object. If false - delete parts to destroy and don’t do destroy.
Show Calculations
Photo
enabled - Bool : enable/disable the calculation show
time - Float : How long calculations will be showed
(IS BUGGY!!!)
Calculations
Photo
Here im start from object calculation.
So, is use SubtractAsync only on object.
region3_calculation:
Is creates a region3 for every destroy part. Find a other parts to destroy(don’t include destroy parts). And use SubtractAsync on this parts.
Here code if you need this:
Code of region3 calculation
function Region3Math(objects)
local partsTable = {}
for index, object in pairs(objects) do
local region3 = Region3.new(object.Position - object.Size/2, object.Position + object.Size/2)
local parts = workspace:FindPartsInRegion3WithIgnoreList(region3, objects)
for index, part in pairs(parts) do
table.insert(partsTable, part)
end
end
local duplicate = duplicatesExist(partsTable)
if duplicate then
table.remove(partsTable, duplicate)
end
return partsTable
end
function duplicatesExist(arr) --returns true if two or more values in array equal, false otherwise
local hash = {}
for i = 1, #arr do
local v = arr[i]
if hash[v] == nil then
hash[v] = i
else
return hash[v]
end
end
return false
end
Plans for the future
-
More settings and feauters, i wanna add particles, character damage in settings, more debris parameters
-
Optimization. Yes i wanna optimize region3 calculation, and just do it better. Also i wanna optimize debris size formula and just do debris without bug and low fps(i think i do custom instance(BUT it will not be soon) or just make debris smaller…)
Where i can test it?
Link to test place: https://www.roblox.com/games/7549264698/Destroy-Test
Module link: https://www.roblox.com/library/7549663550/DestroyModule
File: Destroy Module.rbxl (71.8 KB)
Bugs and etc. can be because is test version of module and i do more fixes and updates
I will be very grateful for finding various bugs and ideas for configuring and optimizing the module. Thanks.