Help with Camera Wobble

I am trying to make a camera wobble for a drunk state in my game. I am using camera cframe matrix alongside a tween in order to achieve this.

I am not getting the results I want and the camera seems to be going in a different direction to where I want it to go.

I haven’t been able to find much on this topic online or I am unsure where to look.

local Run = game:GetService("RunService")
local TS = game:GetService("TweenService")

local DrunkTweenInfo = TweenInfo.new(4, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut)

local Cam = game.Workspace.Camera
local LeftCamWarpData = CFrame.new(0, 0, 0, 1, 0, 0, 0.4, 1, 0, 0, 0, 1)
local RightCamWarpData = CFrame.new(0, 0, 0, 1, 0, 0, -0.4, 1, 0, 0, 0, 1)

local LeftCamWarp = TS:Create(Cam, DrunkTweenInfo, {CFrame = Cam.CFrame * CFrame.new(0, 0, 0, 1, 0, 0, 0.4, 1, 0, 0, 0, 1)})
local RightCamWarp = TS:Create(Cam, DrunkTweenInfo, {CFrame = Cam.CFrame * CFrame.new(0, 0, 0, 1, 0, 0, -0.4, 1, 0, 0, 0, 1)})

Run.RenderStepped:Connect(function()
	while true do
		LeftCamWarp:Play()
		wait(3)
		RightCamWarp:Play()
		wait(3)		
	end
end)

1 Like

This is a local script within StarterPlayerScripts, also.

i’m not really good with camera manipulation!

but!

i have this viewmodel sway code, that could be modified to work with your drunk effect

drunk? someone’s gonna get their game taken down

it looks like this:

-- viewmodel sway variables
	local frequency = 2
	local amplitude = 0.1

	-- weld the viewmodel while adding some sway to it
	rService:BindToRenderStep("WeldViewmodel", Enum.RenderPriority.Camera.Value, function()	
		local offset = math.sin(tick() * frequency) * amplitude
		clonedViewmodel:PivotTo(camera.CFrame + Vector3.new(offset, 0, 0))
	end)

now, i modified it a bit, i’m not sure if it’ll work, but i think you can play around with it:

-- viewmodel sway variables
	local frequency = 2
	local amplitude = 0.1

	-- drunk effect
	rService:BindToRenderStep("DrunkEffect", Enum.RenderPriority.Camera.Value, function()	
		local offset = math.sin(tick() * frequency) * amplitude
		camera.CFrame = CFrame.lookAt(camera.CFrame, camera.CFrame * CFrame.new(offset))
	end)

a really horrible attempt, buuut i hope you can achieve something with that!