Help needed on Battlegrounds camera script!

When I am not in Shiftlock, the camera follows the head nicely:

But, when I activate Shiftlock, the camera doesn’t follow the head correctly, the camera kind of “goes backward” or zooms out because of the head’s animation:

Here is my script:

-- put it inside StarterPlayer>StarterCharacterScripts
task.wait(1.5)
local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local rootpart,head = char:WaitForChild("HumanoidRootPart"),char:WaitForChild("Head")
game:GetService("RunService"):BindToRenderStep("CameraOffset",Enum.RenderPriority.Camera.Value-1,function()
	game:GetService("TweenService"):Create(hum,TweenInfo.new(0.45),{CameraOffset = (rootpart.CFrame+Vector3.new(0,1.5,0)):pointToObjectSpace(head.CFrame.p)}):Play()
end)```

the CameraOffset is relative to your HumanoidRootPart, so Z is forward/back for the character. in shiftlock your character always faces where the camera looks, so whenever the anim moves your head forward or back it pushes the camera in/out along where it’s looking. that’s the “zoom” you’re seeing

just drop the Z and keep X and Y. also making a new tween every frame isn’t great, they all fight each other, so lerp it instead:

--put it inside StarterPlayer>StarterCharacterScripts
local plr = game.Players.LocalPlayer
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local rootpart,head = char:WaitForChild("HumanoidRootPart"),char:WaitForChild("Head")
game:GetService("RunService"):BindToRenderStep("CameraOffset",Enum.RenderPriority.Camera.Value-1,function(dt)
	local offset = (rootpart.CFrame+Vector3.new(0,1.5,0)):pointToObjectSpace(head.CFrame.p)
	hum.CameraOffset = hum.CameraOffset:Lerp(Vector3.new(offset.X,offset.Y,0),math.min(dt*10,1))
end)
hum.Died:Connect(function()
	game:GetService("RunService"):UnbindFromRenderStep("CameraOffset")
end)

the Died part unbinds it on death, otherwise the old one keeps running after you respawn. and you don’t need the task.wait(1.5) since the script runs inside the character anyway

Thanks for the reply! This method already works better.

I was wondering if the camera could also go forward with the head (if you get what I mean)
That the forward/Backward axis also works properly

In this video, what I wanna achieve, the Camera would also go back as the character jumps backwards. Is this possible?

yeah it’s possible, turns out the real issue wasn’t Z itself. i tested it and in shiftlock the camera reads CameraOffset relative to the camera instead of your character, and Z is flipped. so when your head goes back the camera goes forward and the other way around, that’s why it felt like zooming

just convert the offset when shiftlock is on and you can keep the Z:

--put it inside StarterPlayer>StarterCharacterScripts
local plr = game.Players.LocalPlayer
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local rootpart,head = char:WaitForChild("HumanoidRootPart"),char:WaitForChild("Head")
local UIS = game:GetService("UserInputService")
game:GetService("RunService"):BindToRenderStep("CameraOffset",Enum.RenderPriority.Camera.Value-1,function(dt)
	local offset = (rootpart.CFrame+Vector3.new(0,1.5,0)):pointToObjectSpace(head.CFrame.p)
	if UIS.MouseBehavior == Enum.MouseBehavior.LockCenter then
		local cam = workspace.CurrentCamera
		offset = cam.CFrame:VectorToObjectSpace(rootpart.CFrame:VectorToWorldSpace(offset))
		offset = Vector3.new(offset.X,offset.Y,-offset.Z)
	end
	hum.CameraOffset = hum.CameraOffset:Lerp(offset,math.min(dt*10,1))
end)
hum.Died:Connect(function()
	game:GetService("RunService"):UnbindFromRenderStep("CameraOffset")
end)

now the camera should go back with you when you jump backwards in shiftlock too

1 Like

Wow! This works perfectly, just like Strikeborn!
Thanks a lot, I have been looking out for this fix for a ling time