I’m attempting to create a camera system where when you click and drag, you rotate around an object. To achieve this effect, I constantly make the camera face an invisible 1x1x1 part and rotate that part with the click and drag.
The problem I’m having is that the part doesn’t rotate 360 degrees, but rather only 180 or so. Depending on which way the camera is facing (the invisible part slowly rotates), the part rotates at a different degree.
My full script:
local camera = workspace.CurrentCamera
local camPart = workspace:WaitForChild("CameraPart")
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local tweenService = game:GetService("TweenService")
local uis = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local zoom = 8.5
camera.CameraSubject = camPart
camera.CameraType = Enum.CameraType.Fixed
uis.InputChanged:Connect(function(input, gp)
if gp then return end
if input.UserInputType == Enum.UserInputType.MouseWheel then
if input.Position.Z == -1 then
for i = 1, 5 do
if zoom + 0.2 < 13 then
zoom = zoom + 0.2
wait()
else
break
end
end
else
for i = 1, 5 do
if zoom - 0.2 > 4 then
zoom = zoom - 0.2
wait()
else
break
end
end
end
end
end)
runService.RenderStepped:Connect(function()
camera.CFrame = camPart.CFrame * CFrame.new(0, 0, zoom)
end)
uis.InputBegan:Connect(function(input, gp)
if gp then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
rotate = runService.RenderStepped:Connect(function()
local ModelPart = workspace:FindFirstChild("ModelPart")
ModelPart:SetPrimaryPartCFrame(CFrame.new(ModelPart.PrimaryPart.Position, Vector3.new(mouse.Hit.p.X, -mouse.Hit.p.Y, -mouse.Hit.p.Z)))
end)
end
end)
uis.InputEnded:Connect(function(input, gp)
if gp or not rotate then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
rotate:Disconnect()
end
end)