I want the first person camera to lean left when the player walks left, and lean right when the player walks right. What would be the best way to go about it?
So are your game locked in first person? If not, then the following shall be your LocalScript in StarterPlayerScripts:
local Player = game.Players.LocalPlayer
local Character = Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera
local CameraTiltDegree = 2 --this decides how much the camera tilts, you can mess with this one
--if ^ is positive you lean left when you walk left, if it's negative it's the other way around
local DefaultLerpAlpha = 0.145 --this decides how fast the camera tilts, you can mess with this one
local CameraTilt = CFrame.new()
local Action_CameraTilt = function()
local Tilt = Camera.CFrame.RightVector:Dot(Humanoid.MoveDirection) * CameraTiltDegree
CameraTilt = CameraTilt:Lerp(CFrame.Angles(0,0,math.rad(Tilt)),DefaultLerpAlpha)
Camera.CFrame *= CameraTilt
end
local Head = Character:WaitForChild("Head")
local RunService = game:GetService("RunService")
local CameraTiltBind
Head:GetPropertyChangedSignal('LocalTransparencyModifier'):Connect(function()
if Head.LocalTransparencyModifier == 1 then --this checks if player is in first person
CameraTiltBind = RunService.RenderStepped:Connect(function()
task.defer(Action_CameraTilt)
end)
else
if CameraTiltBind then CameraTiltBind:Disconnect() end --this disables the headtilt if player leaves or is not in first person
end
end)
Hope this helps you out! This evolves some mathematics so you might have to look it up yourself.
1 Like