How to turn my NPC in a viewport

Hello,
I’m making a game like piggy, and I need to use viewport frames, I made one for the bot, however it faces the wrong way!
How can I turn it around?
Here is my script:

local ViewportCamera = Instance.new('Camera',script)
ViewportCamera.CameraType = Enum.CameraType.Scriptable


local RunService = game:GetService('RunService')

local Item = game.ReplicatedStorage:WaitForChild('Instances'):WaitForChild('PlayerImage')

local ViewPortPoint = Vector3.new(0,0,0)

local ViewportFrame = script.Parent:WaitForChild('PlayerViewportFrame')

ViewportFrame.CurrentCamera = ViewportCamera

Item:SetPrimaryPartCFrame(CFrame.new(ViewPortPoint))

Item.Parent = ViewportFrame

RunService.RenderStepped:Connect(function()

	local cfrane, size = Item:GetBoundingBox()
	
	local Max = math.max(size.X,size.Y,size.Z)
	
	local Distance = (Max/math.tan(math.rad(ViewportCamera.FieldOfView))) * 2.6
	
	local CurrentDistance = (Max/2) + Distance

	ViewportCamera.CFrame = CFrame.new(ViewPortPoint + Vector3.new(0,0,CurrentDistance,ViewPortPoint))
	
	
end)

What my NPC looks like in the viewport frame( should be the other way)

Thanks for help!

Here’s how:

ViewportCamera.CFrame = CFrame.new(ViewPortPoint + Vector3.new(0,0,CurrentDistance,ViewPortPoint))

We can change angles in CFrame, which can be done by CFrame.Angles().
As you said you want to turn it, you want to turn it 180 degrees, so…

ViewportCamera.CFrame = CFrame.new(ViewPortPoint + Vector3.new(0,0,CurrentDistance,ViewPortPoint)) * CFrame.Angles(0,math.rad(180),0)

here it is.

(P.S. math.rad is a converter, which translates degrees to radian.

I changed my line to this:

ViewportCamera.CFrame = CFrame.new(ViewPortPoint + Vector3.new(0,0,CurrentDistance,ViewPortPoint)) * CFrame.Angles(0,math.rad(180),0)

But now it’s not even on the viewport frame anymore.

That just made it closer

Sorry, I didn’t read your full script. Try this:

ViewportCamera.CFrame = CFrame.new(ViewPortPoint - Vector3.new(0,0,CurrentDistance),ViewPortPoint)
1 Like

This can be done by manipulating the CFrame of the camera in the viewportframe.
It would look something like this:

local origin = someCharacter:GetPrimaryPartCFrame().Position
local offset = origin + Vector3.new(0, 0, -5)

viewportCamera.CFrame = CFrame.new(offset, origin)