Hey everyone, I am currently working on a first-person game. To add a bit more “realism,” I’ve added a bobbing and swaying effect using the Spring module by @Quenty. However, whenever I jump, my micro profiler shows huge lag spikes like the example below:
I first tried to separate the calculations by changing their priority, but nothing worked. I researched debugging, but I didn’t find a solution. So, I am here to ask what could be causing these lags. Here is a part of the controller (Client) that handles the “rendering” of the calculations:
function Local.GetBobbing(Addition: number)
return math.sin(tick() * Addition * 1.3) * 0.5
end
local springs = {
bobbing = Spring.new(),
swaying = Spring.new()
}
local calculatedBobbing = Vector3.new()
local calculatedVelocity = 0
RunService:BindToRenderStep("HeavyCalculations", Enum.RenderPriority.First.Value, function(deltaTime)
calculatedBobbing = Vector3.new(Local.GetBobbing(10), Local.GetBobbing(5), Local.GetBobbing(5))
calculatedVelocity = HumanoidRootPart.Velocity.Magnitude
end)
RunService:BindToRenderStep("SpringUpdates", Enum.RenderPriority.Input.Value, function(deltaTime)
springs.bobbing:shove(calculatedBobbing / 25 * calculatedVelocity / 20)
end)
RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function(deltaTime)
local UpdateBobbleSpring = springs.bobbing:update(deltaTime)
CurrentCamera.CFrame *= CFrame.Angles(math.rad(UpdateBobbleSpring.X), math.rad(UpdateBobbleSpring.Y), math.rad(UpdateBobbleSpring.Z))
Humanoid.CameraOffset = self.Constants.Match_Camera_Offset
end)
Local._bin:Add(function()
RunService:UnbindFromRenderStep("HeavyCalculations")
RunService:UnbindFromRenderStep("SpringUpdates")
RunService:UnbindFromRenderStep("CameraUpdate")
end)
Here is just a part of the Controller.
PS: _bin is simply Janitor for disconnecting the events.
Thank you for your help.