Unable To Change Rotation Of Viewport Frame

Hello! I am trying to make a dialogue system where there is a viewport system that shows who your talking to. Everything works, but it shows you the back of their head rather than the front.


I can’t seem to find out how to change its orientation. Here is the script:

local function setupViewportFrame(characterModel)

	characterViewport:ClearAllChildren()

	local viewportCamera = Instance.new("Camera")
	viewportCamera.Parent = characterViewport
	characterViewport.CurrentCamera = viewportCamera

	local characterClone = characterModel:Clone()
	characterClone.Parent = characterViewport

	local primaryPart = characterClone.PrimaryPart or characterClone:FindFirstChild("HumanoidRootPart") or characterClone:FindFirstChild("Torso") or characterClone:FindFirstChild("UpperTorso")

	if primaryPart then

		characterClone:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0, 0, 0)))

	
		local cameraPosition = primaryPart.Position + primaryPart.CFrame.LookVector * -3 + Vector3.new(0, 1, 0)  -- Adjust as needed
		viewportCamera.CFrame = CFrame.new(cameraPosition, primaryPart.Position + Vector3.new(0, 1, 0))  -- Look at the character's head area


		for _, descendant in pairs(characterClone:GetDescendants()) do
			if descendant:IsA("Decal") or descendant:IsA("Texture") then
				descendant.Parent = descendant.Parent  
			end
		end
	else
		warn("No PrimaryPart found for character model:", characterModel.Name)
	end
end

How would I go about changing its rotation so that it shows the front of the character?

Any help is appreciated!

Are you sure you put the viewport camera in front of the character clone and not behind?

You can try to fix it by just rotating the character’s clone primary part 180 degrees (It should rotate the entire clone to face the camera, I think), or
change the position of the viewport camera to be in front of the character clone (mess around with the numbers, you could change the -3 into 3 see if it works)

1 Like

I don’t know how I missed it but all I had to do was change the -3 to a positive. Thanks!

1 Like

Yeah, you already got the LookVector which is going in front so you were going behind with the -3 . Glad I could help (mark my reply as the answer :D)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.