How to make the camera follow animations?

Im trying to make it where the camera is locked to the players head so it follows it in animations.
I have tried a few player modules which have worked but when I go out of studio and into the actual Roblox client, it glitches like shown below:

I can’t move my character and the camera is fixed in one spot and cant be moved…
if some can help me with this, it will be greatly appreciated.
Thank you!

2 Likes

Interesting, seems like something you would do in battlegrounds game, I would use RunService to set the camera’s position to the head’s position after every renderstep. Something like this:

game:GetService("RunService"):BindToRenderStep("LockCamera", Enum.RenderPriority.Camera.Value - 1, function(dt)
	camera.CFrame = 
		camera.CFrame.Rotation + 
		character.Head.Position
end)

Or, if you want you could apply this same logic and lerp it instead for smoothness.

you are correct on the battlegrounds game thing lol! ill try this and let you know if it works!

1 Like

Issue: the game immediately tries to set the character variable so its becomes nil
I have tried to use WaitForChild but that just yields everything forerver, how would i fix this?

this should work :slight_smile:

-- LOCAL SCRIPT --

-- game > StarterPlayer > StarterCharacterScripts --
-- or
-- game > StarterGui --

task.wait(.5)

local run = game:GetService("RunService")

local cam = workspace.CurrentCamera

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local hum = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")
local head = char:WaitForChild("Head")

run:BindToRenderStep("CamOffset",Enum.RenderPriority.Camera.Value + 1,function()
	if hum.CameraOffset ~= (hrp.CFrame + Vector3.new(0, 1.5, 0)):ToObjectSpace(head.CFrame).Position then
		hum.CameraOffset = (hrp.CFrame + Vector3.new(0, 1.5, 0)):ToObjectSpace(head.CFrame).Position
	end
end)

6 Likes

yes!!! thanks man!!! ive been having this issue for way too long LOL

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.