So for the past day i have been playing with viewports, but i soon found out its pretty hard having viewports scaled, positioned right! :Example
local ViewPortRotation = {
RunService = game:GetService("RunService");
Angles = CFrame.Angles;
Rad = math.rad
}
ViewPortRotation.Enable = function(ViewPort, RotationSpeed)
if ViewPort then
print(ViewPort)
local ViewPortPart = ViewPort:FindFirstChildWhichIsA("Part")
if ViewPortPart then
if ViewPortPart.Name == "LockPart" then
local ViewPortCamera = Instance.new("Camera")
ViewPortCamera.Name = "ViewPortCamera".. ViewPortPart.Name
ViewPort.CurrentCamera = ViewPortCamera
ViewPortCamera.Parent = ViewPort
local StartPosition = ViewPortPart.CFrame
local Rotation = ViewPortRotation.Angles(0, ViewPortRotation.Rad(RotationSpeed), 0)
local RotationCourse = StartPosition * Rotation
RotationCourse = (RotationCourse.lookVector * 10)
local SpinTime = 0
ViewPortRotation.RunService.RenderStepped:Connect(function(d)
SpinTime = SpinTime + d
ViewPortCamera.CFrame = CFrame.new(ViewPortPart.CFrame.p) * CFrame.fromOrientation(0, math.rad(SpinTime * RotationSpeed), 0) * CFrame.new(0, 0, 5)CFrame.new(RotationCourse)
end)
end
end
end
end
return ViewPortRotation
How could i improve this code to have it work as intended?