Tilt camera in movement direction?

I’m making a game solely in first person. I’d like to have the player’s camera tilt slightly in the direction they are moving (i.e. tilt forward a little bit when moving forward)
I’ve found this post that shows how I can do this for left and right movement, however it doesn’t work if i modify it for forwards and backwards movement (it constantly rotates the camera when I move.) and it’s also quite choppy (snapping into place instead of gradually moving)

Anyone know how I would go about doing this? I won’t be able to respond for a while but I’ll try and test any solutions anyone has.

2 Likes
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local camera = workspace.CurrentCamera
player.CameraMode = Enum.CameraMode.LockFirstPerson

local rs = game:GetService("RunService")
local ts = game:GetService("TweenService")

rs.RenderStepped:Connect(function(timeDelta)
	ts:Create(camera, TweenInfo.new(0.1), {["CFrame"] = camera.CFrame + (3 * humanoid.MoveDirection)}):Play()
end)

Is this what you mean?

1 Like

Not really. This offsets the location, not the actual rotation. It’s also quite stuttery.

Are you wondering how to make something seen in most fps games where your able to peak around corners?

Or just the camera moves in the direction the player moves?

Movement in the direction that a player is moving. But the general concept is the same as corner peeking (with rotation instead of just movement)

You could probably make the cameras cframe the current cframe * (move direction * 10) or something along those lines to change the angle.

I’ll write some code that will do it tomorrow and then post it here cause its pretty late.

Try somethile like this

-- Front & Back movement
local forward = humanoidRootPart.CFrame.LookVector:Dot(humanoid.MoveDirection)
-- Left & Right
local strafing = -humanoidRootPart.CFrame.RightVector:Dot(humanoid.MoveDirection)

RunService.RenderStepped:Connect(function()
   camera.CFrame = camera.CFrame:Lerp(camera.CFrame * CFrame.Angles(-math.rad(10 * forward), 0, 0) * CFrame.Angles(0, 0, math.rad(5 * strafing)), 0.5)
end)
4 Likes