So I’m making a game with headbobbing involved and I want to make the game look nice so I had the headbobbing rotate as well but the problem is that this is VERY performance heavy
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera
local running = false
local speed = character.Humanoid.WalkSpeed/2
local RunService = game:GetService("RunService")
local camerabobcf = CFrame.new()
local movingModifier = 0.05
RunService.RenderStepped:Connect(function(dt)
camera.CFrame = camera.CFrame
* camerabobcf
local currTime = tick()
if running then
local bobbleX = math.cos(currTime * speed) * .25
local bobbleY = math.abs(math.sin(currTime * speed)) * .25
local bobble = Vector3.new(bobbleX,bobbleY,0)
local bobbleRotate = CFrame.Angles(0, 0,
math.sin(currTime * speed) * 0.25 * movingModifier
)
camerabobcf = camerabobcf:Lerp(CFrame.new(bobble) * bobbleRotate, 0.1)
else
local idleBobble = Vector3.new(
math.cos(currTime * 0.3) * .25,
math.abs(math.sin(currTime * 0.3)) * .25,
0
)
local idleBobbleRotation = CFrame.Angles(0, 0,
math.rad(math.sin(currTime * 2) * .25)
)
camerabobcf = camerabobcf:Lerp(CFrame.new(idleBobble) * idleBobbleRotation, 0.05)
end
end)
character.Humanoid.Running:Connect(function(WalkSpeed)
if WalkSpeed > 0.1 then
running = true
else
running = false
end
end)
character.Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
speed = character.Humanoid.WalkSpeed/2
end)