Hi. I was wondering how to make the player lean, but keep the camera focused on the player? I tried using other scripts, but they don’t achieve the smooth effects that I wanted. I’m looking to implement it to this script, which makes the player bobble.
local char = game.Players.LocalPlayer.Character
local hrp = char.HumanoidRootPart
local cam = game.Workspace.Camera
local bobblex
local bobbley
local bobble
local other = coroutine.create(function()
while game:GetService("RunService").Heartbeat:Wait() do
if char.Humanoid.MoveDirection.Magnitude > 0 and char.Humanoid.FloorMaterial ~= Enum.Material.Air then
--[[ this line doesnt work ]]-- cam.CFrame = cam.CFrame * CFrame.Angles(0,0, math.rad(45))
char.Humanoid.CameraOffset = char.Humanoid.CameraOffset:lerp(bobble, .3)
else
char.Humanoid.CameraOffset = char.Humanoid.CameraOffset * .85
end
if char.Humanoid.WalkSpeed == 38 then
bobblex = math.sin(tick() * 9) * 1
bobbley = math.abs(math.sin(tick() * 10)) * 1.5
else
bobblex = math.sin(tick() * 6) * 1
bobbley = math.abs(math.sin(tick() * 7)) * 1.5
end
bobble = Vector3.new(bobblex,bobbley,0)
end
end)
coroutine.resume(other)
while game:GetService("RunService").Heartbeat:Wait() do
if char.Humanoid.MoveDirection.Magnitude > 0 then
repeat
cam.FieldOfView += 1
wait()
until cam.FieldOfView > 80
cam.FieldOfView = 80
else
repeat
cam.FieldOfView -= 1
wait()
until cam.FieldOfView < 70
cam.FieldOfView = 70
end
end