Hello, How can I sync up footstep sounds with my trigonometry headbobble?

Hello, I’ve been trying everything to find out how to sync up footstep sounds with the head bobble I made. Here is my head bobble;

runService.RenderStepped:Connect(function(bobble)
	local currentTime = tick()
	local speed = humanoid.WalkSpeed
	--//Create a realistic walk headbobble
	if movementFunctions.CheckMovement() then
		
		local bobbleSpeedX = .1 * (1.57078 * speed)
		local bobbleDistanceX = .35
		
		local bobbleSpeedY = .1 * (3.14157 * speed)
		local bobbleDistanceY = .50
		
		local X = math.cos(currentTime * bobbleSpeedX) * bobbleDistanceX
		local Y = math.abs(math.sin(currentTime * bobbleSpeedY)) * bobbleDistanceY
		local bobble = Vector3.new(X, Y, 0)
		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, .25)
		
		--//Create a random idle breathing camera movement
	end
end)

(this is not the full script I removed extra things that aren’t required for this question)
now I want to play a sound every time the x reaches its down point so every time the blue line touches down which is every second.
image
The problem is I have to incorporate distance and how fast the player is moving so that will throw this off. I’ve made it so far that the head bobble works it will go slower when the player walks slower and vice versa but I want to play a footstep sound when it reaches its down point any ideas?

1 Like

I fixed the problem I made a run service check to check when the CameraOffset goes below a certain number then I added a simple debounce and ran my code.

1 Like