How to make the player able to move their camera by holding right-clik in my custom freecam script?

I’ve tried to ask 3 different AIs, looked at other devforum posts, but I just can’t find something that works…

3 Likes

can you send the script?

dfghedfherherthertherth

1 Like

local mouseDelta = UIS:GetMouseDelta()
local SLOWNESS = 200
local x, y = -mouseDelta.X/SLOWNESS, -mouseDelta.Y/SLOWNESS
Camera.CFrame *= CFrame.Angles(y,x,0)

Just tried this in a heartbeat event

the script work but you needa rotate cam when RMB clicked?

No, it doesn’t work. It doesn’t move

by the way, this script you send is your whole script or some part of it?

It’s a part of my freecam script. I just sent the part where I tried for right-clicking. It’s just in a heartbeat event

can you send the whole script? If no, Im gonna script my own free cam script and send you
oh… Alr… Lemme script my own free cam script

RS.Heartbeat:Connect(function(deltaTime)
if Player:GetAttribute(“BMCamera”) ~= true then return end

if RIGHT_CLICKING == true then
local mouseDelta = UIS:GetMouseDelta()
local SLOWNESS = 200
local x, y = -mouseDelta.X/SLOWNESS, -mouseDelta.Y/SLOWNESS
Camera.CFrame *= CFrame.Angles(y,x,0)
end
end)

Finally, done!
Create a LocalScript in StarterGui and name it like “FreeCam”. To toggle free cam click “L”

local runService = game:GetService("RunService")
local input = game:GetService("UserInputService")
local players = game:GetService("Players")

local Sensitivity = 0.2
local Smoothness = 0.05

local cam = game.Workspace.CurrentCamera
local player = players.LocalPlayer

local character:Model = player.Character or player.CharacterAdded:wait()
local humanoid:Humanoid = character:WaitForChild("Humanoid")
local root:Part = character:WaitForChild("HumanoidRootPart")
local CamPos,TargetCamPos = cam.CoordinateFrame.Position, cam.CoordinateFrame.Position
local AngleX,TargetAngleX = 0,0
local AngleY,TargetAngleY = 0,0
local FreeCamCF = CFrame.new()

local Enabled = false
local Set = false
local w,a,s,d = false, false, false, false

input.InputBegan:Connect(function(inpObj, GPE)
	if not GPE then
		if inpObj.KeyCode == Enum.KeyCode.L then
			Enabled = not Enabled
		end
		if inpObj.KeyCode == Enum.KeyCode.W then
			w = true
		end
		if inpObj.KeyCode == Enum.KeyCode.A then
			a = true
		end
		if inpObj.KeyCode == Enum.KeyCode.S then
			s = true
		end
		if inpObj.KeyCode == Enum.KeyCode.D then
			d = true
		end
	end
end)

input.InputEnded:Connect(function(inpObj)
	if inpObj.KeyCode == Enum.KeyCode.W then
		w = false
	end
	if inpObj.KeyCode == Enum.KeyCode.A then
		a = false
	end
	if inpObj.KeyCode == Enum.KeyCode.S then
		s = false
	end
	if inpObj.KeyCode == Enum.KeyCode.D then
		d = false
	end
end)

local max_angle = 360
local max_x = math.huge

input.InputChanged:connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
		local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness

		local X = TargetAngleX - delta.y
		TargetAngleX = math.clamp(X, -max_x, max_x)
		TargetAngleY = (TargetAngleY - delta.x) % max_angle
	end	
end)

local val = 0.5

runService.Heartbeat:Connect(function()
	if Enabled then
		local offset = CFrame.new()

		if w then
			offset*=CFrame.new(0,0,-val)
		end
		if a then
			offset*=CFrame.new(-val,0,0)
		end
		if s then
			offset*=CFrame.new(0,0,val)
		end
		if d then
			offset*=CFrame.new(val,0,0)
		end

		CamPos = CamPos + (TargetCamPos - CamPos) *0.28
		AngleX = AngleX + (TargetAngleX - AngleX) *0.35
		local dist = TargetAngleY - AngleY
		dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * max_angle or dist
		AngleY = (AngleY + dist *0.35) % max_angle
		cam.CameraType = Enum.CameraType.Scriptable

		cam.CoordinateFrame = CFrame.new(FreeCamCF.Position)
			* CFrame.Angles(0,math.rad(AngleY),0)
			* CFrame.Angles(math.rad(AngleX),0,0)
			* offset

		FreeCamCF = cam.CoordinateFrame

		game.UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
		
		Set = false
	elseif not Set then
		FreeCamCF = cam.CFrame
		
		cam.CameraType = Enum.CameraType.Custom
		game.UserInputService.MouseBehavior = Enum.MouseBehavior.Default
		Set = true
	end
	
	root.Anchored = Enabled
	humanoid.AutoRotate =  not Enabled
end)

local module = {}

–//SERVICES

local TS = game:GetService(“TweenService”)
local RS = game:GetService(“RunService”)

–//GLOBALS

local Player = game.Players.LocalPlayer
local UIS = game.UserInputService
local Camera = workspace.CurrentCamera
local MOVE_SPEED = 0.3
local CAMERA_POINT_OFFSET = Vector3.new(0, 0, -10)
local CAMERA_PIVOT_POINT = Camera.CFrame * CFrame.new(CAMERA_POINT_OFFSET)
local AngleX,TargetAngleX = 0,0
local AngleY,TargetAngleY = 0,0
local FreeCamCF = CFrame.new()

–//STATES

local FORWARD = false
local BACKWARD = false
local LEFT = false
local RIGHT = false
local ROTATING_LEFT = false
local ROTATING_RIGHT = false
local RIGHT_CLICKING = false

RS.Heartbeat:Connect(function(deltaTime)
if Player:GetAttribute(“BMCamera”) ~= true then return end

if FORWARD == true then
Camera.CFrame *= CFrame.new(Vector3.new(0, 0, -MOVE_SPEED))
end
if BACKWARD == true then
Camera.CFrame *= CFrame.new(Vector3.new(0, 0, MOVE_SPEED))
end
if LEFT == true then
Camera.CFrame *= CFrame.new(Vector3.new(-MOVE_SPEED, 0, 0))
end
if RIGHT == true then
Camera.CFrame *= CFrame.new(Vector3.new(MOVE_SPEED, 0, 0))
end
CAMERA_PIVOT_POINT = Camera.CFrame * CFrame.new(CAMERA_POINT_OFFSET)
if RIGHT_CLICKING == true then
local mouseDelta = UIS:GetMouseDelta()
local SLOWNESS = 200
local x, y = -mouseDelta.X/SLOWNESS, -mouseDelta.Y/SLOWNESS
Camera.CFrame *= CFrame.Angles(y,x,0)
end
end)

local max_angle = 360
local max_x = math.huge
local Sensitivity = 0.2
local Smoothness = 0.05

UIS.InputChanged:connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness

  local X = TargetAngleX - delta.y
  TargetAngleX = math.clamp(X, -max_x, max_x)
  TargetAngleY = (TargetAngleY - delta.x) % max_angle

end
end)

return module

It doesn’t do anything

Wait nvm. I see I didn’t change everything correctly

bro, what is this, why module script, lol

I just have everything as modules

alr, just, lemme do this. Just wait

umm, hmhmh, try to do this first. If it wont work I do this

New Version (with right click + wheel movement + shift (speed/2)):

local runService = game:GetService("RunService")
local input = game:GetService("UserInputService")
local players = game:GetService("Players")

local Sensitivity = 0.2
local Smoothness = 0.05

local cam = game.Workspace.CurrentCamera
local player = players.LocalPlayer

local character:Model = player.Character or player.CharacterAdded:wait()
local humanoid:Humanoid = character:WaitForChild("Humanoid")
local root:Part = character:WaitForChild("HumanoidRootPart")
local CamPos,TargetCamPos = cam.CoordinateFrame.Position, cam.CoordinateFrame.Position
local AngleX,TargetAngleX = 0,0
local AngleY,TargetAngleY = 0,0
local FreeCamCF = CFrame.new()

local Enabled = false
local Set = false
local w,a,s,d = false, false, false, false
local right_clicked = false
local shift = false
local wheelUsed = false
local wheelOffset = CFrame.new()

input.InputBegan:Connect(function(inpObj, GPE)
	if not GPE then
		if inpObj.KeyCode == Enum.KeyCode.L then
			Enabled = not Enabled
		end
		if inpObj.KeyCode == Enum.KeyCode.W then
			w = true
		end
		if inpObj.KeyCode == Enum.KeyCode.A then
			a = true
		end
		if inpObj.KeyCode == Enum.KeyCode.S then
			s = true
		end
		if inpObj.KeyCode == Enum.KeyCode.D then
			d = true
		end
		if inpObj.KeyCode == Enum.KeyCode.LeftShift then
			shift = true
		end
		if inpObj.UserInputType == Enum.UserInputType.MouseButton2 then
			right_clicked = true
		end
	end
end)

player:GetMouse().WheelForward:Connect(function()
	wheelOffset = CFrame.new(0,0,-1)
end)

player:GetMouse().WheelBackward:Connect(function()
	wheelOffset = CFrame.new(0,0,1)
end)

input.InputEnded:Connect(function(inpObj)
	if inpObj.KeyCode == Enum.KeyCode.W then
		w = false
	end
	if inpObj.KeyCode == Enum.KeyCode.A then
		a = false
	end
	if inpObj.KeyCode == Enum.KeyCode.S then
		s = false
	end
	if inpObj.KeyCode == Enum.KeyCode.D then
		d = false
	end
	if inpObj.KeyCode == Enum.KeyCode.LeftShift then
		shift = false
	end
	if inpObj.UserInputType == Enum.UserInputType.MouseButton2 then
		right_clicked = false
	end
end)

local max_angle = 360
local max_x = 80

input.InputChanged:connect(function(inputObject:InputObject)
	if inputObject.UserInputType == Enum.UserInputType.MouseMovement and right_clicked then
		local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness
		
		local X = TargetAngleX - delta.y
		TargetAngleX = math.clamp(X, -max_x, max_x)
		TargetAngleY = (TargetAngleY - delta.x) % max_angle
	end	
	if inputObject.UserInputType == Enum.UserInputType.MouseWheel and inputObject.UserInputState == Enum.UserInputState.Change then
		wheelUsed = true
	end
end)

local val = 0.5

local last = Vector3.new()
local new = Vector3.new()

runService.Heartbeat:Connect(function()
	if Enabled then
		local offset = CFrame.new()
		
		if w then
			offset*=CFrame.new(0,0,-val)
		end
		if a then
			offset*=CFrame.new(-val,0,0)
		end
		if s then
			offset*=CFrame.new(0,0,val)
		end
		if d then
			offset*=CFrame.new(val,0,0)
		end
		
		CamPos = CamPos + (TargetCamPos - CamPos) *0.28
		AngleX = AngleX + (TargetAngleX - AngleX) *0.35
		local dist = TargetAngleY - AngleY
		dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * max_angle or dist
		AngleY = (AngleY + dist *0.35) % max_angle
		cam.CameraType = Enum.CameraType.Scriptable
		
		if shift then
			offset = CFrame.new(offset.Position/2)
		end
		
		cam.CFrame = CFrame.new(FreeCamCF.Position)
			* CFrame.Angles(0,math.rad(AngleY),0)
			* CFrame.Angles(math.rad(AngleX),0,0)
			* offset
		
		if wheelUsed then
			cam.CFrame *= wheelOffset
			wheelUsed = false
		end
		
		FreeCamCF = cam.CFrame

		if right_clicked then
			game.UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
		else
			game.UserInputService.MouseBehavior = Enum.MouseBehavior.Default
		end
		
		Set = false
		
		val = math.clamp(val, 0.5, 3)

		if offset.Position.Magnitude>0 then
			val += 0.001
		else
			val = 0.5
		end
	else
		FreeCamCF = cam.CFrame
		val = 0.5
		
		if not Set then
			cam.CameraType = Enum.CameraType.Custom
			game.UserInputService.MouseBehavior = Enum.MouseBehavior.Default
			Set = true
		end
	end
	
	root.Anchored = Enabled
	humanoid.AutoRotate =  not Enabled
end)