Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// Point of the module is to offer clean and seamless transformation between two models.
- local function ScaleModel(Model, TargetModel)
- local Humanoid, HumRP = Model:WaitForChild("Humanoid"), Model:WaitForChild("HumanoidRootPart")
- local Torso = Model:WaitForChild("Torso")
- local NewTorso = TargetModel:WaitForChild("Torso")
- local CharacterSize, NewModelSize = Torso.Size, NewTorso:GetExtentsSize()
- local PrimaryCFrame = Torso.CFrame
- local Scale = NewModelSize.Y / CharacterSize.Y
- Humanoid.HipHeight *= Scale
- Scale = Vector3.one * Scale
- for _,Component in ipairs(Model:GetDescendants()) do
- if Component:IsA("Part") then
- Component.Size *= Scale
- elseif Component:IsA("Motor6D") and Component.Parent ~= HumRP then
- Component.C0 = CFrame.new(Component.C0.p * Scale) * (Component.C0 - Component.C0.p)
- Component.C1 = CFrame.new(Component.C1.p * Scale) * (Component.C1 - Component.C1.p)
- elseif Component:IsA("Attachment") then
- Component.Position *= Scale
- end
- end
- end
- local function ChangeModelTransparency(Model, Value)
- for _,Component in Model:GetDescendants() do
- if not Component:IsA("Part") then
- continue
- end
- Component.Transparency = Value
- end
- end
- return function (Model, TargetModel)
- local Humanoid, HumRP = Model:WaitForChild("Humanoid"), Model:WaitForChild("HumanoidRootPart")
- --// First, we scale the "Model" to the size of the "TargetModel"
- ScaleModel(Model, TargetModel)
- ChangeModelTransparency(Model, 1)
- --// Then, we weld all the pieces of TargetModel, onto Model, like a morph.
- for _,Limb in TargetModel:GetChildren() do
- --// Every model consists of sub-models which are named after the limbs.
- if not Limb:IsA("Model") then
- continue
- end
- Limb = Limb:Clone()
- local Root = Limb.PrimaryPart
- local TargetLimb = Model:FindFirstChild(Limb.Name)
- if not TargetLimb then
- error("Couldn't find target limb: "..TargetModel.Name)
- end
- Limb:PivotTo(TargetLimb.CFrame)
- Limb.Parent = TargetLimb
- local WeldConstraint = Instance.new("WeldConstraint")
- WeldConstraint.Part0, WeldConstraint.Part1 = TargetLimb, Root
- WeldConstraint.Parent = Root
- end
- --// Guard clause to ensure our new model is fully visible.
- ChangeModelTransparency(TargetModel, 0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement