Problem with making the camera for the game

Im trying to make a custom camera for the game (the one like in strategy games). And it all works well, I have problem with making the camera rotation. I mean, it does work, but only with Mouse button1, and not button2.
The way my script works, is it detects when user is holding down Button1. When he does that, script saves the X value of mouse, and then calculates delta of that X value and new X value which is used as rotate angle. But it requires mouse to move, while when user holds down Mouse2, the mouse is stuck in place which results in script not working.

Script
local CameraPos, CameraRot = BASE_CAMERA_POS, BASE_CAMERA_ROT
local IsHolding, MouseHitPos, CurrentRot = false, 0, 0

Mouse.Button1Down:Connect(function()
	MouseHitPos = Mouse.X
	IsHolding = true
end)
Mouse.Button1Up:Connect(function()
	IsHolding = false
	CurrentRot = CurrentRot + ((MouseHitPos - Mouse.X) / 2)
end)

RunService.RenderStepped:Connect(function()
	Camera.CameraType = Enum.CameraType.Custom
	
	if IsHolding == true then
		local MouseDelta = (MouseHitPos - Mouse.X) / 2
		CameraRot = BASE_CAMERA_ROT + Vector3.yAxis * (CurrentRot + MouseDelta)
	end
	
	CameraPart.Position = CameraPos
	CameraPart.Orientation = CameraRot
	Camera.CFrame = CameraPart.CFrame
end)
Demonstration

Is there any other way I can do that?

2 Likes

Found out how to do this. I must use UserInputService:GetMouseDelta().X which calculates mouse delta when Button2 is held.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.