How do i making camera bobbing like this one

Hello, DevForumer.
Right now I want to know how I can do this camera bobbing. I really want to do this. And it’s been a week now. How I figure out how to make a camera like this

So I tried asking my friend, and he said it was a spring module to do this. I have been trying to figure out how to use the spring module until now I am discouraged so I created this post to ask you guys for help.

If you can help me I would like to thank you so much! :heart:

My English might look a bit bad if you can’t read it, I’m sorry. I am asian And English is not my main language! :sweat_smile:

video link

External Media
4 Likes

Make a gui with a black frame in it and make a local script with a tween that goes up and down forever

As for the first person mode go to Explorer > StarterPlayer > CameraMode and change it to LockFirstPerson

I am not referring to screengui, I am referring to its camera offset.

I don’t really know if the camera is offset so im guessing the camera is locked to first person mode

you don’t have to use spring for this, you can just lerp the camera based on the character’s velocity for the bending and some basic sine wave calculation for the bobbing

local runService = game:GetService("RunService")

local plr = game.Players.LocalPlayer
local chr = plr.Character
local humrootpart = chr:WaitForChild("HumanoidRootPart")
local hum = chr:WaitForChild("Humanoid")
local cam = workspace.Camera

local tiltSpeedZ = 0.1
local bobbingSpeed = 0.1

local tilt = 0
local sinValue = 0

function lerp(a, b, t)
	return a + (b - a) * t
end

function calculateSine(speed, intensity)
	sinValue += speed 
	if sinValue > (math.pi * 2) then sinValue = 0 end
	local sineY = intensity * math.sin(2 * sinValue)
	local sineX = intensity * math.sin(sinValue)
	local sineCFrame = CFrame.new(sineX, sineY, 0)
	return sineCFrame
end

local previousSineX = 0
local previousSineY = 0
runService.RenderStepped:Connect(function(dt)
	local movementVector = cam.CFrame:vectorToObjectSpace(humrootpart.Velocity / math.max(hum.WalkSpeed, 0.01))
	local speedModifier = (hum.WalkSpeed / 16)
	tilt = math.clamp(lerp(tilt, movementVector.X * tiltSpeedZ, 0.1), -0.25, 0.1) 

	local sineCFrame = calculateSine(bobbingSpeed * speedModifier, movementVector.Z * speedModifier)
	local lerpedSineX = lerp(previousSineX, sineCFrame.X, 0.1)
	local lerpedSineY = lerp(previousSineY, sineCFrame.Y, 0.1)

	cam.CFrame *= CFrame.Angles(0, 0, tilt) * CFrame.new(lerpedSineX, lerpedSineY, 0)
	previousSineX = lerpedSineX
	previousSineY = lerpedSineY
end)

which will create a similar effect

40 Likes

Thank you, You’re such a kind people!

5 Likes