Object rotation in Viewport Frames

Hi, how do I make it so that the object isn’t flat (like 90 degrees positioned up). Here is my code:

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

local R = 0

local Item = workspace:WaitForChild("OneCoin")

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

local FiftyCoinViewportFrame = script.Parent.FiftyCoins

FiftyCoinViewportFrame.CurrentCamera = ViewportCamera

Item:SetPrimaryPartCFrame(CFrame.new(ViewportPoint))

Item.Parent = FiftyCoinViewportFrame

game:GetService("RunService").RenderStepped:Connect(function()
	
	local cframe, size = Item:GetBoundingBox()
	
	local Max = math.max(size.X,size.Y,size.Z)
	
	local Distance = (Max/math.tan(math.rad(ViewportCamera.FieldOfView))) * 4
	
	local CurrentDistance = (Max/2)* Distance
	
	ViewportCamera.CFrame = CFrame.Angles(0, math.rad(R),0) * CFrame.new(ViewportPoint + Vector3.new(0,0,CurrentDistance), ViewportPoint)
	R = R+1
end)

Here’s a better explanation: the image below is a coin in the viewport. As you can see, it’s flat. How do I rotate it 90 degrees so that you can see the full coin?

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

local R = 0

local Item = workspace:WaitForChild("OneCoin")

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

local FiftyCoinViewportFrame = script.Parent.FiftyCoins

FiftyCoinViewportFrame.CurrentCamera = ViewportCamera

Item:SetPrimaryPartCFrame(CFrame.new(ViewportPoint) * CFrame.Angles(math.pi/2, 0, 0)) --> May have to change axis

Item.Parent = FiftyCoinViewportFrame

game:GetService("RunService").RenderStepped:Connect(function()
	
	local cframe, size = Item:GetBoundingBox()
	
	local Max = math.max(size.X,size.Y,size.Z)
	
	local Distance = (Max/math.tan(math.rad(ViewportCamera.FieldOfView))) * 4
	
	local CurrentDistance = (Max/2)* Distance
	
	ViewportCamera.CFrame = CFrame.Angles(0, math.rad(R),0) * CFrame.new(ViewportPoint + Vector3.new(0,0,CurrentDistance), ViewportPoint)
	R = R+1
end)
4 Likes