Moving Camera Around Axis

Hello. I’ve been looking for a solution to my problem, and cannot seem to find one. I am trying to make my camera move around an axis that is my character whenever the mouse is clicked and dragged. For example: say I clicked my mouse and dragged the screen to the right. This should cause the camera to move around the axis to the left, as is:

image

I’m assuming I need mouse delta to do this. Here’s my script so far (which only detects mouse clicks and mouse delta):

local module = {}

function module:initiate(plr, ui, network, util, assets, event, script)
	
	local action = util.service "ContextActionService"
	local uis = util.service "UserInputService"
	local runtime = util.service "RunService"
	
	local cam = workspace.CurrentCamera
	
	local blank = Vector3.new()
	local mousedown = false
	local mdelta = blank
	
	action:BindAction("MouseMovement", function(name, state, input)
		local delta = input.Delta
		if delta == blank then return end
		mdelta = delta
	end, false, Enum.UserInputType.MouseMovement)
	
	action:BindAction("Mouse1Hold", function(name, state, input)
		if state ==  Enum.UserInputState.Begin then
			uis.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
			mousedown = true
		elseif state == Enum.UserInputState.End or state == Enum.UserInputState.Cancel then
			uis.MouseBehavior = Enum.MouseBehavior.Default
			mousedown = false
		end
	end, false, Enum.UserInputType.MouseButton1)
	
end

return module

How can I make it so the camera faces toward the character and moves around the character according to where the camera is dragged?

If anything I talked about was inconclusive please let me know and I will try to elaborate.

1 Like

Make a renderStepped function and just

workspace.Camera.CFrame *= CFrame.Angles(0, 0, -math.rad(10))

Since when does += and *= syntax exist in ROBLOX Lua? Anyways, I understand this much, but it needs to be based on my mouse movement while holding click.

This post doesn’t really clarify what problem you’re actually stuck on.

Moving around an axis is done simply with

CFrame.fromAxisAngle(Vector3.new(0,1,0), radians)

Using the Y axis pole because you want it to rotate around the character. Incidentally, you can create a ratio of radians-per-pixel with your own sensitivty setting or getting the user’s custom sensitivity (from the Escape > settings menu) using UserSettings()

1 Like

It does exist, I’ve used it alot of times

what do you still want to know? could you give MrNicNac a solution because I think he solved it?