Rotating image in ViewPortFrame

Hey developers!
Today I tried to make rotating viewport frame.I made this script, but it says in output (GetBoundingBox() is not valid member of “that viewportframe”
please help, thanks :slight_smile:

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

local y = .8
local x = 4

local R = 0

local audi = workspace:WaitForChild("TestCar")

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

local ViewPortFrame = script.Parent:WaitForChild("CarImage")

ViewPortFrame.LightDirection = Vector3.new(0,1,0)

ViewPortFrame.Ambient = Color3.fromRGB(255,255,255)

ViewPortFrame.CurrentCamera = ViewPortCamera

audi:SetPrimaryPartCFrame(CFrame.new(ViewPortPoint))

audi = ViewPortFrame

game:GetService("RunService").RenderStepped:Connect(function()
	
	local ofrane, size = audi:GetBoundingBox()
	
	local Max = math.max(size.X,size.Y,size.Z)
	
	local Distance = (Max/math.tan(math.rad(ViewPortCamera.FieldOfView))) * x
	
	local CurrentDistance = (Max/2) + Distance
	
	ViewPortCamera.CFrame = CFrame.Angles(0,math.rad(R),0) * CFrame.new(ViewPortPoint + Vector3.new(0,0,CurrentDistance),ViewPortFrame)
	
	R = R +1
end)
1 Like

erm, don’t you mean:
audi.Parent = ViewPortFrame

this is the only thing you do with R; you don’t set the rotating to R for example.
and instead of the following:

ever frame it will add 1 to R and not the time per frame times 1
I suggest making it:

game:GetService("RunService").RenderStepped:Connect(function(stepTime)
	-- other script
	
	-- instead of R += 1 is the same as R = R + 1 do:
	R += 1 * stepTime
end)
2 Likes

Thanks for solution. Will try it now.

1 Like