PlaybackLoudness too shaky when screen shaking to audio

Hi there, my playbackloudness script allows the screen to shake to the audio, however it is too shaky. I am very new to lua. Also, the function inside this script is to be toggled on and off by a button or after the song ends (another script with a music playlist). Things like tweening is way too complicated for me but I do want to use tweening in this script.

local RunService = game:GetService("RunService")
local Button = script.Parent
local musicplayer = workspace.Sound
local CurrentCamera = workspace.CurrentCamera

local ScreenShakeSettings = {
	CameraMinFOV = 70,
	CameraMaxFOV = 80,
	CameraMaxVolume = 1500
}

local connected = false

local function changeCameraShakeState()
	if not connected then
		game:GetService("RunService"):BindToRenderStep("CurrentTrack", 1, function()
			local CurrentLoudness = musicplayer.PlaybackLoudness
			local FOV = ScreenShakeSettings.CameraMinFOV + (ScreenShakeSettings.CameraMaxFOV - ScreenShakeSettings.CameraMinFOV) * (CurrentLoudness / ScreenShakeSettings.CameraMaxVolume)
			if FOV > 0 and FOV < 130 then
				CurrentCamera.FieldOfView = FOV
			end
		end)
	else
		RunService:UnbindFromRenderStep("CurrentTrack")
	end
	connected = not connected
end

Button.MouseButton1Click:Connect(changeCameraShakeState)

Your best bet would to try tweening the FOV instead of using the raw numbers.

Edit: Sorry I missed that last part about tweens being too complicated but I found this: How to Tween Field of View? - #7 by inHeadspace

yeah, i do not know how to do that, sorry

Check my edit. I used that solution in a script i made a while back, it may help you.

where is the edit?


Edit is right here^
Any more info you need can probably be found in the tweening documentation.

If it’s simply giving you numbers that are too big (and thusly shaking the screen too much), you can do some simple math on it (eg halving it, times by 0.75, stuff like that) so the numbers getting fed into the “shake screen” part are a lot smaller and thusly won’t shake as much.

no
do not use tweenservice for things that update every frame like this

instead, interpolate the fieldofview to make it less shaky

2 Likes

i saw this post but didnt know how it would work on mine https://devforum.roblox.com/t/screen-shaking-to-audio-a-little-too-shaky/1018088

Interpolate is deprecated, instead you need to use tweenservice.

i dont mean the Camera:Interpolate function i mean a manual one
here is what i mean

local rs = game:GetService("RunService")

local function step(a,b,c)
   return (b-a)*math.min(c,1);
end;

local shakiness=8;
local cam=workspace.CurrentCamera;

rs.RenderStepped:Connect(function(dt)
     cam.FieldOfView+=step(cam.FieldOfView,workspace.Sound.PlaybackLoudness/10+60,dt*shakiness);
end);
2 Likes

Oh, that makes sense. Sorry about that.