Hello guys, I want to ask, so I have a viewport frame rendering a dummy, the camera should be fine. But why everytime I add a model (like you know hat giver) to that model, suddenly the viewportframe camera becomes too far. Below is the video.
Latest Script
Morph Handler
local Morph = {}
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Customization = ReplicatedStorage.Customization
local function Weld(character, part, model, types)
local Folder = character:FindFirstChild(types) ~= nil and character:FindFirstChild(types) or Instance.new('Folder')
Folder.Name = types
Folder.Parent = character
character:FindFirstChild(part).Transparency = 1
if part == 'Head' then
character:FindFirstChild(part).face.Transparency = 1
end
local g = model:Clone()
g.Name = part
g.Parent = Folder
for i, v in pairs(g:GetChildren()) do
if v:IsA("BasePart") then
local W = Instance.new("Weld")
W.Part0 = g.Middle
W.Part1 = v
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:Inverse() * CJ
local C1 = v.CFrame:Inverse() * CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
end
local Y = Instance.new("Weld")
Y.Part0 = character:FindFirstChild(part)
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0
end
local h = g:GetChildren()
for i = 1, # h do
h[i].Anchored = false
h[i].CanCollide = false
end
end
local function MorphFunc(Character, Model, Types)
local Children = Model:GetChildren()
for i = 1, #Children do
Weld(Character, Children[i].Name, Children[i], Types)
end
end
function Morph.new(Character, Types, Name)
local MorphRoot = Customization[Types]:FindFirstChild(Name, true)
print(MorphRoot)
local MorphClone = MorphRoot:Clone()
print(MorphClone)
MorphFunc(Character, MorphClone, Types)
end
return Morph
Local Script
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Morph = require(ReplicatedStorage.Morph)
local DevTrooper = script.DevTrooper
local viewportFrame = script.Parent.ViewportFrame
DevTrooper.Parent = viewportFrame
DevTrooper.PrimaryPart = DevTrooper.UpperTorso
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
viewportCamera.FieldOfView = 1
viewportCamera.MaxAxisFieldOfView = 1
viewportCamera.CFrame = CFrame.new(Vector3.new(-200,-100,0), DevTrooper.Head.Position)
task.spawn(function()
while task.wait() do
DevTrooper:SetPrimaryPartCFrame(DevTrooper.UpperTorso.CFrame * CFrame.Angles(0,0.03,0))
end
end)
task.wait(10)
local userMorph = Morph.new(DevTrooper, 'Morph', 'Trooper')
local Morph = {}
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Customization = ReplicatedStorage.Customization
local function Weld(character, part, model, types)
local Folder = character:FindFirstChild(types) ~= nil and character:FindFirstChild(types) or Instance.new('Folder')
Folder.Name = types
Folder.Parent = character
character:FindFirstChild(part).Transparency = 1
if part == 'Head' then
character:FindFirstChild(part).face.Transparency = 1
end
local g = model:Clone()
g.Name = part
g.Parent = Folder
for i, v in pairs(g:GetChildren()) do
if v:IsA("BasePart") then
local W = Instance.new("Weld")
W.Part0 = g.Middle
W.Part1 = v
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:Inverse() * CJ
local C1 = v.CFrame:Inverse() * CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
end
local Y = Instance.new("Weld")
Y.Part0 = character:FindFirstChild(part)
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0
end
local h = g:GetChildren()
for i = 1, # h do
h[i].Anchored = false
h[i].CanCollide = false
end
end
local function MorphFunc(Character, Model, Types)
local Children = Model:GetChildren()
for i = 1, #Children do
Weld(Character, Children[i].Name, Children[i], Types)
end
end
function Morph.new(Character, Types, Name)
local MorphRoot = Customization[Types]:FindFirstChild(Name, true)
print(MorphRoot)
local MorphClone = MorphRoot:Clone()
print(MorphClone)
MorphFunc(Character, MorphClone, Types)
end
return Morph
Local Script
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Morph = require(ReplicatedStorage.Morph)
local DevTrooper = script.DevTrooper
local viewportFrame = script.Parent.ViewportFrame
DevTrooper.Parent = viewportFrame
DevTrooper.PrimaryPart = DevTrooper.UpperTorso
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
viewportCamera.FieldOfView = 1
viewportCamera.MaxAxisFieldOfView = 1
viewportCamera.CFrame = CFrame.new(Vector3.new(-200,-100,0), DevTrooper.Head.Position)
task.spawn(function()
while task.wait() do
DevTrooper:SetPrimaryPartCFrame(DevTrooper.UpperTorso.CFrame * CFrame.Angles(0,0.03,0))
end
end)
task.wait(10)
local userMorph = Morph.new(DevTrooper, 'Morph', 'Trooper')