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.
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)
-- 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)