Realistic Jumping Using Camera

Hello,

I’m trying to create a realistic jumping system where the camera bobs up when you jump and down slightly when you land, I’ve seen this done in many games but I can’t figure out how to do it.

Here’s an example:

I’ve checked through the DevForum and countless YouTube videos but I’m not finding anything related to what I need, or the topic just doesn’t contain any useful information. I’m aware that I’m supposed to use StateChanged on the Humanoid to detect when they jump and land, I just can’t figure out the CameraOffset bit and how to manipulate the vectors. Any help would be appreciated, thanks!

I believe the way the clip you provided achieved this is through a mixture of tweening the CameraOffset property and using the spring module. Running a quick function like this when the player jumps/lands should do the job (sorry if the code has some issues, I wrote this without access to checking it in studio):

local plr = game:GetService("Players").LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local human = character:WaitForChild("Humanoid")

local tweenService = game:GetService("TweenService")

local function changeCameraOffset(offset)
	local tween = tweenService:Create(human, TweenInfo.new(.1), {CameraOffset = offset}) -- play around with this part so it doesn't look too mechanical
	tween:Play()
end

I can’t tell if your clip shows the camera tilting a bit or not, but if it does you can try using the lerp function or the spring module to change the camera’s orientation along side tweening the camera’s offset.

2 Likes

No, CameraOffset does not rotate the camera at all, they use CFraming. You can use a spring module to make this happen.

I think you could use different Easing Styles

EasingStyle | Documentation - Roblox Creator Hub

check out “Back” easing style

1 Like

Using this SpringModule.rbxm (1.3 KB), you can achieve it using something like:

local spring = Spring.new()
-- when he lands/jumps
local bobble = getBobbing() -- should return a Vector3
spring:shove(bobble / 10 * (HumanoidRootPart.Velocity.Magnitude) / 10)

local newSpringValue - spring:Update(deltaTime)

camera.CFrame = camera.CFrame:ToWorldSpace(CFrame.new(newSpringValue.Y, newSpringValue.X, 0))

A typical getBobbing function should be something like this:

local function getBobbing()
	return Vector3.new(
		math.sin(tick() * 10 * 1.3) * 0.5,
		math.sin(tick() * 5 * 1.3) * 0.5,
		math.sin(tick() * 5 * 1.3) * 0.5,
	)
end

Edit the 5 and 10 as you want but from past user this seems like the perfect value.

2 Likes

is there not a more simple way to go about it?

Not exactly, if you mean the actual bobbing, then no. If you mean the spring part, then yes. You can use any other spring module like spr, or simply, TweenService though springs feels way better and more natural.

This might help: CameraService