Camera Offset Change When Entering First Person?

How could I maybe change the Players Humanoid ‘Camera Offset’ when the player enters first person?
Additionly how could I make the transition smooth (Because most games so a kinda glide or tweening of the camera to place it in the new offset position) and make sure that Shift Lock doesn’t interfere? (This is because for me, shift lock moves the players camera slightly backwards, making the camera offset unaligned.)

Just to show a solution that I’ve programmed myself:

local runService = game:GetService("RunService")

local character = script.Parent
local humanoid = character.Humanoid
local head = character.Head

local camera = workspace.CurrentCamera

runService.RenderStepped:Connect(function()
	local distance = (head.Position - camera.CFrame.Position).Magnitude
	humanoid.CameraOffset = distance <1.5 and Vector3.new(0, 0, -1) or Vector3.new(0, 0, 0)
end)

This script doesn’t add any of the smooth tweening or Shift Lock prevention that I would idealy want to add and I think it might be too unefficient because it checks every time the render has stepped.

Any possible solutions or redirections would be greatly appreciated! Sorry if this post was a little long or confusing, I just wanted to make sure that all the details where there.

Hey! A little confused about whether your problem is, is the camera offset not changing when you are in first person? Also you can detect if the player is using shift lock by UIS.MouseBehaviour and check if its using lock center.

Hey, sorry if It was a little confusing! In most horror games I play on roblox, there seems to be an identical way of handling first person? Like when ever I enter first person theres a little smooth transition to changing the cameras offset and it disables shift lock. Because it looks and acts so simmilar I was wondering if it was like an inbuilt thing or plugin?

Hey, this is actually a bug that’s presented itself because of your modified camera function, I’m using a similar camera-to-head style function that was presenting the same issue to me. Here’s how I fixed it:

Inside of the default PlayerModule inside of the BaseCamera module
(PlayerModule > CameraModule > BaseCamera)

On line ~364 we have a function that adjusts our cameraOffset while shiftlock (mouselocked) is enabled, it should look like this:

if self:GetIsMouseLocked() then
	cameraOffset = Vector3.new()
end

SO, all we gotta do is replace this with something that doesn’t create this offset, and we’ll do it only in first person using the function we already have in PlayerModule.

Here’s what your solution should look like:

if self:GetIsMouseLocked() or (self.IsInFirstPerson and self:IsInFirstPerson()) then
	cameraOffset = Vector3.zero
end

Hope this helps! I know I’m late, but a game could always use the camera to follow the head, especially with custom character animations.

As someone who’s had to do similar (to what I’d guess you’re trying to say) for a bodycam game, I think you’re looking for this:

-- This NEEDS to be placed under StarterCharacterScripts
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local humanoid = player.Character and player.Character:WaitForChild("Humanoid")

-- offsets you want (adjust accordingly)
local firstPersonOffset = Vector3.new(0, 0, -1)
local thirdPersonOffset = Vector3.new(0, 0, 0)

local function setCameraOffset(offset, duration)
	local tween = TweenService:Create(humanoid, TweenInfo.new(duration, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {CameraOffset = offset})
	tween:Play()
end

-- Renderstepped for smooth transitions and checking
RunService.RenderStepped:Connect(function()
	local camera = workspace.CurrentCamera
	local distance = (player.Character.Head.Position - camera.CFrame.Position).Magnitude

	if distance < 1.5 then
		-- first-person: smooth transition
		if humanoid.CameraOffset ~= firstPersonOffset then
			setCameraOffset(firstPersonOffset, 0.25)
		end
	else
		-- third-person: smooth transition back
		if humanoid.CameraOffset ~= thirdPersonOffset then
			setCameraOffset(thirdPersonOffset, 0.25)
		end
	end
end)

You can also improve first-person detection as right now it only checks if the distance between the head and camera is less than 1.5. Instead, you could detect it based on UserInputService scrolling or camera zoom

Please mark this as a solution if this works to your needs!

Adding on to this, the CurrentCamera has a property called “Focus”, you can calculate the distance from the Character and the Camera using this. I also found this a lot more reliable, since yesterday I had an issue where if I calculated the Distance from the Head or Player:DistanceFromCharacter, it wouldn’t be as accurate as calculating the distance between the Camera’s Focus and the Camera’s position.

– short example

local camera = workspace.CurrentCamera
local distance = (camera.Focus.Position - camera.CFrame.Position).Magnitude