Hey, I’m trying to use viewport frames for my custom character selection GUI, I need it to work with every character without having to do it manually (basically through script)
Example of what I need - I’m confused on how I’d manipulate the viewport frame to work alongside the character
you can create a camera in front of the character’s face and set this camera to parameter “CurrentCamera” of viewport frame. And a simple script on the camera like:
local run=game:GetService("RunService")
local camera=workspace.CharacterCamera -- camera object
local character=workspace.CharacterExample --- character model
run.RenderStepped:Connect(function()
camera.CFrame=CFrame.new(character.Head.Position+Vector3.new(0,0,5))
end)
I don’t remember exactly the cframe, but something like this
Viewport frames only show what is inside of them. You would have to clone the character model and put it inside of the viewport frame. Then you can adjust the position of the character and camera just like you would normally.
As long as each of the custom characters have the same proportions and are positioned/oriented the same you should only need to get one of them to be compatible with a viewport frame in order for all of them to be compatible with a viewport frame.
local function playericon()
script.Parent["Character Icon"].Viewport.WorldModel:ClearAllChildren()
Character.Archivable = true
local characterclone = Character:Clone()
characterclone.Parent = script.Parent["Character Icon"].Viewport
local player = game.Players.LocalPlayer
local head = Character:WaitForChild("Head")
local RunService = game:GetService("RunService")
local RATE_PER_SECOND = 2
local increment = RATE_PER_SECOND * 1
local pos = head.Position
local lookAt = head.Position
local cameraCFrame = CFrame.new(pos, lookAt)
workspace.CurrentCamera.CFrame = cameraCFrame
script.Parent["Character Icon"].Viewport.CurrentCamera = workspace.CurrentCamera
workspace.CurrentCamera.Parent = script.Parent["Character Icon"].Viewport
end
Tried my best with this? Not sure, is working out with it d’ you think you can help