Rebind Camera Panning

How can I remove the camera panning keybind (press and holding MouseButton2), and instead use something like Mouse | Roblox Creator Documentation to pan the camera so the player doesn’t have to click anything on their mouse?

I don’t get the question you are asking. Do you want the player to move the camera without him clicking the mouse?

1 Like

Yes, and the camera would move as normal but instead just by moving the mouse.

So if I understood correctly, for instance, like the camera moves when Shift Lock is applied?

Yep, just without the camera offset of course.

I think there was a camera type called “Atach”, try change the camera type to that

Then you would have to set UserInputService.MouseBehavior to LockedCenter, every Frame get the MouseDelta (using UserInputService:GetMouseDelta()), and use the X and Y values.

1 Like

So to get the X/Y positioning I do UserInputService:GetMouseDelta().X and UserInputService:GetMouseDelta().Y, do I then set the X and Y positions of the CurrentCamera CFrame to the Delta X/Y?

I’d take an approach like:

camera.CFrame = camera.CFrame * CFrame.Angles(deltaX, deltaY, 0)

DeltaX and DeltaY aren’t necessarily placed this way on CFrame.Angles(), but I don’t have the ability to test it it right now to tell you.

Is this correct?

RunService.RenderStepped:Connect(function()
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
	local deltaX = UserInputService:GetMouseDelta().X
	local deltaY = UserInputService:GetMouseDelta().Y
	Camera.CFrame = Camera.CFrame * CFrame.Angles(deltaX, deltaY, 0)
end)

Should work, make sure to put deltaX and deltaY in math.rad() as CFrame.Angles() requires radians, and also so the numbers will be proportional to the mouse movement.
Edit:

RunService.RenderStepped:Connect(function()
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
	local deltaX = UserInputService:GetMouseDelta().X
	local deltaY = UserInputService:GetMouseDelta().Y
	Camera.CFrame = Camera.CFrame * CFrame.Angles(math.rad(deltaX), math.rad(deltaY), 0)
end)

Did that, controls became almost inverted and there’s really weird movements. It is moving by mouse which is good, but the CFrames are very off.

Found a simpler way.
First, disable the default Key for rotation, MouseButton2, using the following post:

And I wrote this code that should work:

local contextActionService = (game:GetService("ContextActionService"));
local userInputService = (game:GetService("UserInputService"));
local runService = (game:GetService("RunService"));

local camera = (workspace.CurrentCamera);
local MOVEMENT_SPEED = (10);
function RenderStep(dt)
	userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
	local delta = userInputService:GetMouseDelta()
	local a = camera.CFrame;
	local b = camera.CFrame * CFrame.Angles(math.rad(delta.Y), math.rad(delta.X), 0);
	camera.CFrame = a:Lerp(b, dt * MOVEMENT_SPEED)
end;

runService.RenderStepped:Connect(RenderStep)

Edit note: The invert issue happened because of misplacing delta.X and delta.Y inside the CFrame.Angles(), and the weird movement is caused by default rotation interfering with the new rotation.

That definitely improved it, but still some weird movements.

That’s because the default roblox rotation is still applied for some odd reason.
In case the MouseBehavior is set to LockedCenter or LockCurrentPosition, it automatically rotates on it’s own. Therefore, you should not to rotate the camera. Try:

local userInputService = (game:GetService("UserInputService"));
local runService = (game:GetService("RunService"));

function RenderStep(dt)
	userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
    -- // If the mouse Icon is bothering you, just set UserInputService.MouseIconEnabled to false.
end;

runService.RenderStepped:Connect(RenderStep)
1 Like

userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter is already in the RenderStep function.

Yes, but just remove the part that sets the Camera’s Rotation

camera.CFrame = ...

Because Roblox already includes the rotation for you.
Edit: Just tested it, and it seems to work well.

1 Like

Oh wow, that works perfectly. Thank you so much!

1 Like