I am developing a bobbing system for my game, that scales off of the players speed. The problem is that i dont know what math i should use. I do know that i can increase the speed by doing something with the tick(). I have tried multiplying the tick() with the velocity divided by ten, and the problem with that is that the tick() variable gets extreme differences when accelerating. But otherwise it would work. Simply adding the velocity actually works, but only when accelerating. When going at a constant speed, its slower then when accelerating. Can someone give a suggestion on how i would go about fixing this? Thank you!
Script (without scaling with velocity)
--Variables
local rs = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local physical = game.Workspace[plr.Name]
local camera = workspace.CurrentCamera
--Bob script
rs.RenderStepped:Connect(function(dt)
local velocity = physical.HumanoidRootPart.AssemblyLinearVelocity.Magnitude
if velocity > 1 then
local bobx = math.sin(tick())
local boby = math.abs(math.cos(tick()))
local bob = Vector3.new(bobx, boby, 0)
physical.Humanoid.CameraOffset = physical.Humanoid.CameraOffset:Lerp(bob, 0.25)
end
end)