Me and many others scripters are using os.clock/tick for the camera bobbing, but that creates some weird effects. As we know os.clock always changes, which helps for sine function to create these sine waves. The problem is that… os.clock goes by itself.
Let just say your camera Y has a function for when we walk:
math.sin(os.clock())
for example. Here’s the catch: Whenever we try to walk, sine will be at the os.clock’s desire. So the starting point of camera bobbing depends on the os.clock, which means that sometimes sine can be 0.9 when we walk (which makes camera noticebly jump upwards at the start) or something like -0.6 (which also makes camera noticebly jump downwards). Is there any fix to this?
I have this script:
-- {{SERVICES}}
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
-- {{VARIABLES}}
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character.Humanoid
local speed = humanoid.WalkSpeed / 1.1
local distance = .4
humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
speed = math.round(humanoid.WalkSpeed / 1.1)
end)
local camera = workspace.CurrentCamera
camera.FieldOfView = 90
RunService.RenderStepped:Connect(function()
print(math.sin(os.clock()))
if humanoid.MoveDirection ~= Vector3.new() then
humanoid.CameraOffset = humanoid.CameraOffset:Lerp(Vector3.new(0, math.sin(os.clock()), 0), distance)
else
--humanoid.CameraOffset = humanoid.CameraOffset * (1 - distance)
end
end)
(it’s purely for showing what I mean.)
put this script in starterplayerscripts. In your output you’ll see coeffiecent of the sine, and you’ll notice that it’s changing whenever it wants, and the main problem is that the starting point is at the coeffiecent. Try to press W when it shows 0.999 and when it shows -0.999 and you’ll see the fast jump.