EDIT: SMOOTH ISSUES ARE THOSE STUTTERING THING TRANSITIONING BETWEEN REGULAR AND OFFSET CFRAME
For a little bit of context, ive never made bobbing before beceause i thought it was too difficult and boring math ive never used. But yesterday i realized it is actually quite easy to make, following a guide post on this forum explaining everything i needed to know.
Ive been trying to make this TPS bobbing view messing with the camera Z orientation and the results are here tho, i am now stuck with a “smooth” issue.
At first i was using the :Lerp() function as you can see here:
local rs = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local hum = plr.Character:FindFirstChild("Humanoid")
local cam = workspace.CurrentCamera
local sprint = script.Parent.Parent.sprint.sprint
rs.RenderStepped:Connect(function()
local currentTime = tick()
if hum.MoveDirection.Magnitude > 0 then
local walkBobble = cam.CFrame * CFrame.Angles(0, 0, math.cos(currentTime * 12 / 2.5) * 0.1)
local sprintBobble = cam.CFrame * CFrame.Angles(0, 0, math.cos(currentTime * 24 / 2.3) * 0.1)
if sprint.Value == false then
cam.CFrame = cam.CFrame:Lerp(walkBobble, .2)
else
cam.CFrame = cam.CFrame:Lerp(sprintBobble, .5)
end
end
end)
The first issue i had using :Lerp() is that when walking/running, there was no in between when transitioning from camera CFrame to the offset CFrame as we can see in this clip:
After that, i thought about using TweenService and did so but i doesnt fix my issue and actually make it more buggy:
local rs = game:GetService("RunService")
local ts = game:GetService("TweenService")
local plr = game.Players.LocalPlayer
local hum = plr.Character:FindFirstChild("Humanoid")
local cam = workspace.CurrentCamera
local sprint = script.Parent.Parent.sprint.sprint
local normalCFrame = cam.CFrame
local ti = TweenInfo.new(.35, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
rs.RenderStepped:Connect(function()
local currentTime = tick()
local walkTween = ts:Create(cam, ti, {CFrame = cam.CFrame * CFrame.Angles(0, 0, math.cos(currentTime * 12 / 2.5) * 0.1)})
local sprintTween = ts:Create(cam, ti, {CFrame = cam.CFrame * CFrame.Angles(0, 0, math.cos(currentTime * 24 / 2.3) * 0.5)})
local baseTween = ts:Create(cam, ti, {CFrame = normalCFrame})
if hum.MoveDirection.Magnitude > 0 then
if sprint.Value == false then
sprintTween:Cancel()
walkTween:Play()
end
if sprint.Value == true then
walkTween:Cancel()
sprintTween:Play()
end
end
end)