Been trying to make an orbit camera inside a viewport frame, and I got it working but the movement of the camera is really jittery and can lag behind when the player is moving their camera too quickly. I think it has something to do with the LookVector, but I'm not sure.
The code I'm using:
local RunService = game:GetService("RunService")
local Viewport = script.Parent.ViewportFrame
local playerCamera = workspace.CurrentCamera
local vpfCamera = Instance.new("Camera") --Creates new Camera
vpfCamera.Parent = Viewport --Sets it inside the VPF
Viewport.CurrentCamera = vpfCamera --Sets the VPF's Current Camera to it
local offsetDistance = 128
RunService.Heartbeat:Connect(function()
--local mag = (Vector3.new(0,0,0) - playerCamera.CFrame.Position).Magnitude
local thing = vpfCamera.CFrame.LookVector*-offsetDistance --I have no idea what to call this
vpfCamera:PivotTo(CFrame.new(thing)*playerCamera.CFrame.Rotation)
end)
** You are now Level 3! **