SHOW:
|
|
- or go back to the newest paste.
| 1 | local module = {}
| |
| 2 | ||
| 3 | --[[ | |
| 4 | ||
| 5 | Author: TigerCaptain | |
| 6 | Date: 22/09/2018 | |
| 7 | ||
| 8 | Usage example: | |
| 9 | ||
| 10 | local thanos = require("Thanos")
| |
| 11 | thanos:Vanish(workspace.Model) | |
| 12 | ||
| 13 | API: | |
| 14 | @params object: an instance object, if it is a part, it will only run on that part, | |
| 15 | but if it is not a part, then it will run on all of its descendants. | |
| 16 | Vanish( Instance object ) | |
| 17 | ||
| 18 | PROPERTIES: | |
| 19 | tween_info: The TweenInfo object, storing the tween pattern for all parts | |
| 20 | base_properties: A base property for all tweening objects | |
| 21 | ||
| 22 | --]] | |
| 23 | ||
| 24 | local TS = game:GetService("TweenService")
| |
| 25 | local tween_info = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out) | |
| 26 | local base_properties = {Transparency = 1}
| |
| 27 | ||
| 28 | --[[ | |
| 29 | This function copies the <original> table and returns it | |
| 30 | @params original: the original table you are copying | |
| 31 | @return: a copy of the original table | |
| 32 | --]] | |
| 33 | local function CopyTable(original) | |
| 34 | local t = {}
| |
| 35 | for i,v in pairs(original) do | |
| 36 | if type(v) == "table" then | |
| 37 | t[i] = CopyTable(v) | |
| 38 | else | |
| 39 | t[i] = v | |
| 40 | end | |
| 41 | end | |
| 42 | return t | |
| 43 | end | |
| 44 | ||
| 45 | --[[ | |
| 46 | This function combines the <new> table with <base_properties> | |
| 47 | @params new: the additional table you want to merge with the base_properties | |
| 48 | @return: the combined table | |
| 49 | --]] | |
| 50 | local function AddProperties(new) | |
| 51 | local prop = CopyTable(base_properties) | |
| 52 | for i,v in pairs(new) do | |
| 53 | prop[i] = v | |
| 54 | end | |
| 55 | return prop | |
| 56 | end | |
| 57 | ||
| 58 | --[[ | |
| 59 | This function sorts objects based on its position in the world. | |
| 60 | @params: part1, part2: These two will be compared | |
| 61 | @return: true if part1 is further from origin (0,0,0) than part2 | |
| 62 | --]] | |
| 63 | local function AngleSort(part1, part2) | |
| 64 | local s1, s2 = part1.Position, part2.Position | |
| 65 | return s1.Magnitude > s2.Magnitude | |
| 66 | end | |
| 67 | ||
| 68 | --[[ | |
| 69 | This function will return a table of all the descendants in the parent | |
| 70 | @params: parent: The parent holding all descendants | |
| 71 | class (optional): will sort all descendants of a single class | |
| 72 | TODO: Make it a list of classes | |
| 73 | @return: A table of descendants, filtered if desired | |
| 74 | --]] | |
| 75 | local function GetDescendants(parent, class) | |
| 76 | local all_descendants = parent:GetDescendants() | |
| 77 | if class == nil then return all_descendants end | |
| 78 | local filtered_descendants = {}
| |
| 79 | for i,v in pairs(all_descendants) do | |
| 80 | if v:IsA(class) then | |
| 81 | filtered_descendants[#filtered_descendants+1] = v | |
| 82 | end | |
| 83 | end | |
| 84 | return filtered_descendants | |
| 85 | end | |
| 86 | ||
| 87 | --[[ | |
| 88 | This function directly runs the tween on an object | |
| 89 | @params: part: the part being changed | |
| 90 | --]] | |
| 91 | local function VanishPart(part) | |
| 92 | local properties = AddProperties({CFrame = part.CFrame + part.Position.unit*10})
| |
| 93 | local tween = TS:Create(part, tween_info, properties) | |
| 94 | tween:Play() | |
| 95 | end | |
| 96 | ||
| 97 | --[[ | |
| 98 | This function goes through all base parts in a parent directory and applies the | |
| 99 | VanishPart() method upon it. | |
| 100 | @params: model: the directory to run upon. | |
| 101 | --]] | |
| 102 | local function VanishModel(model) | |
| 103 | local descendents = GetDescendants(model, "BasePart") | |
| 104 | table.sort(descendents, AngleSort) | |
| 105 | for i,v in pairs(descendents) do | |
| 106 | v.Anchored = true | |
| 107 | VanishPart(v) | |
| 108 | if i%3 == 0 then | |
| 109 | wait() | |
| 110 | end | |
| 111 | end | |
| 112 | end | |
| 113 | ||
| 114 | --[[ | |
| 115 | This method determines what function to call depending on its object type | |
| 116 | @params: object: the instance to apply the function | |
| 117 | --]] | |
| 118 | function module:Vanish(object) | |
| 119 | if object:IsA("BasePart") then
| |
| 120 | VanishPart(object) | |
| 121 | else | |
| 122 | VanishModel(object) | |
| 123 | end | |
| 124 | end | |
| 125 | ||
| 126 | return module |