Model in Viewport Frame not rotating propetly

I am using Viewport Frame to display player’s custom character in my game. These custom characters are located in Replicated Storage, like this:


structure

Here’s my Local Script inside the GUI:

local character = game:GetService("ReplicatedStorage"):WaitForChild("Characters"):WaitForChild("PlayerCharacters"):WaitForChild(game:GetService("Players").LocalPlayer.Name)
local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0.3, 0, 0.4, 0)
viewportFrame.Position = UDim2.new(0, 15, 0, 15)
viewportFrame.BackgroundColor3 = Color3.new(0, 0, 0)
viewportFrame.BorderColor3 = Color3.new(0.6, 0.5, 0.4)
viewportFrame.BorderSizePixel = 2
viewportFrame.BackgroundTransparency = 0.25
viewportFrame.Parent = script.Parent
local model = character:Clone()
model:SetPrimaryPartCFrame(CFrame.new(0, 0, 0))
model:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
model:WaitForChild("Humanoid").HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
model.Parent = viewportFrame
local viewportCamera = Instance.new("Camera")
viewportCamera.Parent = viewportFrame
viewportCamera.CFrame = CFrame.new(viewportCamera.CFrame.Position, character.HumanoidRootPart.Position)
viewportFrame.CurrentCamera = viewportCamera

Here’s how my character displays:
viewport f

Thanks for help,
Jermartynojm

First of all, go easy on yourself! No need to instance in the Viewport Frame at runtime - build it in Studio! It’ll end up looking better in terms of UI design. If you need it to hide/show, change its Visible property, or clone it from Replicated Storage.

Also, your character is incredibly small because the viewport camera is too far away. Consider offsetting it from the character, like so:

local BACKING = 5
local base = character:GetPrimaryPartCFrame()
local pos = base.Position-base.LookVector*BACKING
viewportCamera.CFrame = CFrame.new(pos,base.Position)

Experiment with the BACKING constant until you reach the desired magnification. Hope it works!

Of course I can build the thing before runtime. But I was just tesing and that’s why I did like this.

There is a small problem. Look here:
output

Edit: You know the third line I gave you? I made a horrible mistake. That minus sign should in fact be a plus sign.

In short, rewrite that line like this:

local pos = base.Position+base.LookVector*BACKING

Works perfectly fine! Thanks.
output2

I also thought about zooming in the avatar a little like AvatarBust (ThumbnailType) does. How can I do that?

AvatarBust > The returned thumbnail shows the bust (chest up) of the user’s avatar.

I’m aware of the upper bust thumbnail API, but to mimic this behaviour on a viewport frame, you’d need to centre on the head rather than the default primary part (HumanoidRootPart).

Swap the code I gave you for this:

local BACKING = 5
local base = character.Head.CFrame
local pos = base.Position+base.LookVector*BACKING
viewportCamera.CFrame = CFrame.new(pos,base.Position)

In short, change the second line to the Head’s CFrame. I also highly recommend you to decrease BACKING and decrease the viewport camera’s Field of View (property).

I changed 4th line a little so it zooms the model more:

viewportCamera.CFrame = CFrame.new(pos + Vector3.new(0,0,2),base.Position)

New look:
o3

Old look (without zooming):
o4

Thanks for your help!

Great work! I’d have to argue, especially for non-viewport scenarios, my method is more reliable. The same result can be gotten from changing the BACKING constant to 2 - that basically controls the zoom level.

Thanks for the information! Changed the code as you said.
I am new to Viewport Frames as I just found about them few days ago. I am going to practice making things with them in the future!

Sure! With characters, what you’re doing is spot-on… but just remember when it’s best to take a picture of your items (particularly products) manually, so you can make them look glamarous in Photoshop or whatnot.

But with characters, what you’re doing is fine.