How would I go about making a rotational camera that can be dragged with a mouse around a object

I’m trying to make a rotational camera that can be dragged while holding left mouse button down, it also focuses or circles a specific object in the workspace

e.g
robloxapp-20220302-1732106.wmv (1.4 MB)

I tried messing with tween service but that got me nowhere, there also aren’t any tutorials out there similar to what im trying to achieve.

Any provided help or explanation would be greatly appreciated
Thanks

1 Like

Use UserInputService.InputChanged to detect mouse movement when the mouse button is held. It’s either the Position or Delta property of the passed InputObject. Then rotate the camera based on the X and Y components of that.

I’ve been trying your solution, it sounds like you’re right. The only problem is that I don’t know how to exactly set up all of the information you explained into a script. If you don’t mind, could you provide an example?

Here’s something to get you started, it’s untested though so there might be typos or whatever. Oh, and it might be that you need the Position of the input object, not the Delta.


function rotateCamera(amount)
    --rotate the camera
end

--Setup drag begin when mouse button is pressed
InputS.InputBegan:Connect(function(beganInput)
    if not beganInput.UserInputType == Enum.UserInputType.MouseButton1 then return end

    --Setup dragging when mouse is moved while mouse button is pressed
    local changedC
    changedC = InputS.InputChanged:Connect(function(changedInput)
        rotateCamera(changedInput.Delta)
    end)

    --Setup drag ending when mouse button is released
    local endedC
    endedC = InputS.InputEnded:Connect(function(endedInput)
        if not beganInput.UserInputType == Enum.UserInputType.MouseButton1 then return end
        changedC:Disconnect()
        endedC:Disconnect()
    end)
end)

Is there any particular way I should set this script up?, e.g putting the script in StarterPlayerScripts. Also is there anything in the code I should change before testing, e.g the first function: rotatecamera(amount)

Is the camera supposed to orbital (constant y, rotates facing object from slightly above it) or able to move in all directions?