360 view around an object using mouse movement?

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)
3 Likes

The 1x1x1 part idea shouldn’t be put into use in this situation, I’d recommend having more than 3 parts wrapping the head, that is the reason why it isn’t going full 360, you will then need to code the speed of the cameras ( as I tried making this before but it just kept going crazy and spinning all over the place ).

1 Like

I believe you can just do

local camPart = workspace:WaitForChild("CameraPart")
wait(1)
workspace.CurrentCamera.CameraSubject = camPart
1 Like

Do you mean having 3+ parts and then letting the player pick which side they want to look at, thereby jumping to another part? I could do that however it wouldn’t give the freedom and effect that I want. Here’s an example of what I’m trying to accomplish:

https://i.gyazo.com/53e94a4855d9b51e8c120ade51c16509.gif

1 Like

I do set the camera subject… The issue I am having is rotating the 1x1x1 part in a fully 3D way.

Ah, I didn’t understand correctly, try this instead

local camPart = workspace:WaitForChild("CameraPart")
local ModelPart = workspace:WaitForChild("ModelPart")
local camera = workspace.CurrentCamera
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local down = false

mouse.TargetFilter = ModelPart
wait(1)
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = camPart

mouse.Button1Down:Connect(function()
	down = true
	repeat wait()
	           ModelPart:SetPrimaryPartCFrame(CFrame.new(ModelPart.PrimaryPart.Position, Vector3.new(mouse.Hit.p.X, -mouse.Hit.p.Y, -mouse.Hit.p.Z)))
until down == false
end)

mouse.Button1Up:Connect(function()
	down = false
end)

I didn’t change that much.

2 Likes

You’re using mouse.Button1Down instead of UserInputService. That doesn’t change much, and it still doesn’t fix the rotational problem.

Weird, it worked fine for me?