Hello, this is a basic method to load characters within a ViewportFrame.
MEDIA
https://gyazo.com/e12e81fc877bc9c4f624f77e583be60a
First place a ScreenGui into StarterGui
then you can place a ViewportFrame and LocalScript into the ScreenGui.
Here is the local script, it has a mini tutorial within it.
--1). Setup some variables and grab the ViewportFrame
local viewport = script.Parent:WaitForChild("ViewportFrame")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local zoom = -5
--2). Create a camera and place it inside of the viewport frame
local camera = Instance.new("Camera")
camera.Parent=viewport
viewport.CurrentCamera = camera
--3). Create an invisible part that will 'control' the cameras orbit easily.
local invisiblePart = Instance.new("Part")
invisiblePart.Size = Vector3.new(1,1,1)
invisiblePart.Transparency = 1
invisiblePart.Parent=viewport
invisiblePart.Orientation = Vector3.new(0,180,0)
--4). Make the character archivable so you can clone certain instances.
--store all cloned parts into a new model, and add the model into viewportframe
local clonedModel
function addCharacter()
character.Archivable=true
local bodyParts = character:GetChildren()
clonedModel = Instance.new("Model")
for i = 1, #bodyParts do
local b = bodyParts[i]
if(b:IsA("Humanoid")
or b:IsA("Accessory")
or b:IsA("MeshPart") or b:IsA("BasePart")
or b:IsA("Pants") or b:IsA("Shirt") or b:IsA("ShirtGraphic")
or b:IsA("BodyColors"))then
newTable[b.Name]=b.Name
if(b.Archivable == false)then
b.Archivable = true
local clone = b:Clone()
clone.Parent = clonedModel
b.Archivable = false
else
local clone = b:Clone()
clone.Parent = clonedModel
end
if(b:IsA("Humanoid"))then
b.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
b.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
end
end
end
clonedModel.Parent = viewport
local ore = invisiblePart.Orientation
invisiblePart.CFrame = clonedModel.HumanoidRootPart.CFrame
--just incase you decide to apply character updates
invisiblePart.Orientation=ore
end
function removeCharacter()
if(clonedModel) then
clonedModel:Destroy()
end
end
--5).add the character to viewport frame and Use RenderStepped for camera & part updates
addCharacter()
game:GetService("RunService").RenderStepped:Connect(function()
--makes the camera orbit around the character model.
invisiblePart.CFrame = invisiblePart.CFrame * CFrame.Angles(0,math.rad(0.5),0)
camera.CFrame = invisiblePart.CFrame + invisiblePart.CFrame.lookVector * zoom
end)
hopefully this helps some people, if you find any bugs or have any improvements then please notify me here, enjoy!