Make the camera "tilt" when moving the mouse and going back to normal when the mouse stop moving

this doesnt work on mobile.
altho I got a solution for the “glitch” when moving backwards (actually a stutter)

1 Like

on line 38, just change the easingtime from 1 to .1

change this
local easingtime = 1

to this
local easingtime = .1

altho it just lerps it smoothly, it still works.

2 Likes

Mobile support @MizterZen @ItsJust_MeJxy

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 
-- StarterCharacterScripts -- 					
--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--
--	Place this into StarterCharacterScripts							--
--	CREDIT																--
--	WhoBloxxedWho; for the initial script								--
--	DoogleFox; some stuff ripped from his panner script					--
--	DuruTeru; shoving it all into this script and then some :)			--
--	Pupermuper; tilt and mobile support
--																		--
--	UPDATE: turned it into r15, made it so you can swim right in water	--
--  Jan 07, 2017														--
--  UPDATE: added walkspeed easing directionally, also adding running   --	
--  Nov 13, 2020 REMOVED for mobile											--
--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--	--


---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 


repeat wait() until game:GetService("Players").LocalPlayer.Character ~= nil
local runService = game:GetService("RunService")
local input = game:GetService("UserInputService")
local players = game:GetService("Players")
local UserInputService = game:GetService"UserInputService"
local ContextActionS = game:GetService("ContextActionService")

-- you can mess with these settings
---Basics---
CanViewBody = true 		-- whether you see your body
Sensitivity = 0.4		-- anything higher would make looking up and down harder; recommend anything between 0~1
Smoothness = 0.1		-- recommend anything between 0~1
FieldOfView = 80		-- fov
---Tilt---
EnabledTilt = true		-- Enable tilt when you mouse your mouse
TiltSpeed = 0.5 		-- recommend anything between 0~5 (normal value = 0.5)
MaximumTilt = 80		-- between 0-90		-- enable tilt
----------
HeadOffset = CFrame.new(0,0.5,-0.5)

local cam = game.Workspace.CurrentCamera
local player = players.LocalPlayer
local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Icon = "rbxassetid://569021388"
local character = player.Character or player.CharacterAdded:wait()
local human = character.Humanoid
local humanoidpart = character.HumanoidRootPart

workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable

local head = character:WaitForChild("Head")
local CamPos,TargetCamPos = cam.CoordinateFrame.p,cam.CoordinateFrame.p 
local AngleX,TargetAngleX = 0,0
local AngleY,TargetAngleY = 0,0
local previousSineX = 0
local previousSineY = 0
local NewInputCam = Vector3.new(0,0,0)
TiltSpeed *= 0.01
local Tilt = 0

local SetUpTilt = false

wait(3)--load

--------------------------------MOBILE OR PC--------------------------------

local Mobile = false

if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled then
	Mobile = true
elseif not UserInputService.TouchEnabled and UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
	Mobile = false
end

--------------------------------VIEW BODY--------------------------------

function updatechar()

	for _, v in pairs(character:GetChildren())do
		if CanViewBody == true then
			if v.Name == 'Head' then
				v.LocalTransparencyModifier = 1
				v.CanCollide = false
				v.face.LocalTransparencyModifier = 1
			end
		else
			if v:IsA'Part' or v:IsA'UnionOperation' or v:IsA'MeshPart' then
				v.LocalTransparencyModifier = 1
				v.CanCollide = false
			end
		end
		if v:IsA'Accessory' then
			v:FindFirstChild('Handle').LocalTransparencyModifier = 1
			v:FindFirstChild('Handle').CanCollide = false
		end
		if v:IsA'Hat' then
			v:FindFirstChild('Handle').LocalTransparencyModifier = 1
			v:FindFirstChild('Handle').CanCollide = false
		end

	end

end

-- math, thx roblox wiki
function lerp(a, b, t)
	return a * (1-t) + (b*t)
end

--------------------------------MOBILE TILT--------------------------------

if Mobile == true then
	if EnabledTilt == true then
		UserInputService.TouchMoved:Connect(function(InputCam,StateOfCam,CamMovement)
			if StateOfCam == false then
				if InputCam.Delta ~= Vector3.new(0,0,0) then -- "~=" is if not equals to
					NewInputCam = InputCam -- Delta
					SetUpTilt = true
				end
			end
		end)
	end
end

--------------------------------SCIPT THAT RUNS ON EVERY FRAME--------------------------------

runService.RenderStepped:connect(function()
	
	--------------------------------PC TILT--------------------------------
	
	if Mobile == false then
		if EnabledTilt == true then
			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
			ContextActionS:BindAction("CameraMovement", function(CamMovement,StateOfCam,InputCam)
				if InputCam.Delta ~= Vector3.new(0,0,0) then -- "~=" is if not equals to
					NewInputCam = InputCam -- Delta
					SetUpTilt = true
				end
			end, false, Enum.UserInputType.MouseMovement)
		end
	end
	
	--------------------------------SCRIPT TILT--------------------------------
	
	if SetUpTilt == true then
		--print(NewInputCam.Delta)
		local delta = Vector2.new(NewInputCam.Delta.x/Sensitivity,NewInputCam.Delta.y/Sensitivity) * Smoothness
		local TiltX = NewInputCam.Delta.x
		local MaxTiltNew = MaximumTilt*0.01

		Tilt = math.clamp(lerp(Tilt, TiltX * TiltSpeed, 0.1), -MaxTiltNew, MaxTiltNew)

		local sineCFrame = math.sin(TiltX * Sensitivity)
		local lerpedSineX = lerp(previousSineX, sineCFrame, 0.1)
		local lerpedSineY = lerp(previousSineY, sineCFrame, 0.1)
		cam.CFrame *= CFrame.Angles(0, 0, -Tilt) * CFrame.new(0, lerpedSineY * 1, 0)


		local X = TargetAngleX - delta.y 
		TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X 
		TargetAngleY = (TargetAngleY - delta.x) %360

		previousSineX = lerpedSineX
		previousSineY = lerpedSineY
	end
	
	--------------------------------MAIN SCRIPT--------------------------------

	updatechar()

	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)) * 360 or dist 
	AngleY = (AngleY + dist *0.35) %360
	cam.CoordinateFrame = CFrame.new(head.Position) 

		* CFrame.Angles(0,math.rad(AngleY),0)
		* CFrame.Angles(math.rad(AngleX),0,Tilt)
		* HeadOffset-- offset

	humanoidpart.CFrame=CFrame.new(humanoidpart.Position)*CFrame.Angles(0,math.rad(AngleY),0)
	
end)

---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 
5 Likes

@ItsJust_MeJxy @Puper_Muper
Thanks!

1 Like

Hello!
Is there a way to disable or edit the camera bobbing? I already have a bobbing script and both of them clash with each other. Thanks!

1 Like