Want to move the camera to the player head

Hi all, sorry for my bad english.
I made a localscript that lets you see your body in first person and when you press right click it rotates the upper torso, but the camera stays in the old head position. I’ve been trying to make the camera move to the head position and still being able to rotate the camera but i don’t know how.

This is the localscript:

local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()
local aiming = false
local humanoid = character:WaitForChild("Humanoid")
local mouse = player:GetMouse()
local head = character:WaitForChild("Head")
local neck = head:WaitForChild("Neck")
local Offset = neck.C0.Y
local upperTorsoWaist = character:WaitForChild("UpperTorso").Waist

character.Humanoid.CameraOffset = Vector3.new(0, 0, -1.0)
uis.MouseIconEnabled = false

if character then
	for i, v in pairs(character:GetDescendants()) do
		if v:IsA("BasePart") and v.Name ~= "Head" then

			v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
				v.LocalTransparencyModifier = v.Transparency
			end)

			v.LocalTransparencyModifier = v.Transparency

		end
	end
end

uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
		aiming = true
	end 
end)

uis.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
		aiming = false
	end 
end)

game:GetService("RunService").RenderStepped:Connect(function()
	if player.Character then
		local point = mouse.Hit
		local vector = character.HumanoidRootPart.CFrame:ToObjectSpace(point).LookVector

		if aiming then
			upperTorsoWaist.C0 =  CFrame.new(0, upperTorsoWaist.C0.Y, 0) * CFrame.Angles(vector.Y,0,0)
		end
		neck.C0 = CFrame.new(0,Offset,0) * CFrame.Angles(vector.Y, -vector.X,0)
	end
end)

This is when you aren’t aiming


And when you aim

1 Like

Could you just change the CameraSubject to the character’s head or lerp the player’s Humanoid.CameraOffset property?

Edited: Your english is very good btw

Thank you, i tried changing the CameraSubject to the head but i can’t rotate the player

Could you try to lerp the Humanoid.CameraOffset property?

1 Like

Here is the basic idea:

local uis = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

uis.InputBegan:Connect(function(input, process)
	if input.UserInputType == Enum.UserInputType.MouseButton2 and not process then
		
		for i = 1, 100, 1 do
			hum.CameraOffset = hum.CameraOffset:Lerp(char:WaitForChild("Head").Position - workspace.CurrentCamera.CFrame.Position, i)
			task.wait()
		end
		
	end
end)

the script isn’t tested, so it may have some small bugs or typos in it. It should find the difference between the camera’s position and the head’s position, then adjust your CameraOffset to the position of your character’s head. Obviously, you have to do the reverse on InputEnded by setting the CameraOffset back to 0, 0, 0

I don’t know, i’ve been doing this since 2 hours this is the script now

local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()
local aiming = false
local humanoid = character:WaitForChild("Humanoid")
local mouse = player:GetMouse()
local head = character:WaitForChild("Head")
local neck = head:WaitForChild("Neck")
local Offset = neck.C0.Y
local upperTorsoWaist = character:WaitForChild("UpperTorso").Waist
local camera = game.Workspace.CurrentCamera
local hrp = character:WaitForChild("HumanoidRootPart")

uis.MouseIconEnabled = false
if character then
	for i, v in pairs(character:GetDescendants()) do
		if v:IsA("BasePart") and v.Name ~= "Head" then

			v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
				v.LocalTransparencyModifier = v.Transparency
			end)

			v.LocalTransparencyModifier = v.Transparency

		end
	end
end

uis.InputBegan:Connect(function(input, process)
	if input.UserInputType == Enum.UserInputType.MouseButton2 and not process then
		aiming = true

	end 
end)

uis.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
		aiming = false
		humanoid.CameraOffset = Vector3.new(0, 0, -1.0)
		upperTorsoWaist.C0 = CFrame.new(-0, 0.2, 0) * CFrame.Angles(0, 0, 0)

	end 
end)

game:GetService("RunService").RenderStepped:Connect(function()
	if player.Character then
		local point = mouse.Hit
		local vector = character.HumanoidRootPart.CFrame:ToObjectSpace(point).LookVector



		if aiming then

			upperTorsoWaist.C0 = upperTorsoWaist.C0:Lerp(CFrame.new(0, upperTorsoWaist.C0.Y, 0) * CFrame.Angles(vector.Y,0,0), .1)
			humanoid.CameraOffset = humanoid.CameraOffset:Lerp(head.Position - hrp.Position, 0.1) 

		end

		--neck.C0 = CFrame.new(0,Offset,0) * CFrame.Angles(vector.Y, 0,0)
	end
end)

camera stills doesnt go to the head, i tried doing the humanoid Root Part instead of camera, because if it is camera, it adds the value that moved away and it just gets away

I think you can just set the CameraSubject to the player’s head