Follow the head with freely moving the camera?

So i’ve been searching for this for SOO long and couldnt find any solution, what i wanna do is that when im on first person, i want my camera to follow the head’s position and orientation, but when i do it it just follows it, and i can no longer move my camera freely, what i mean with this, is, for example: an animation that rotates/moves the player’s head plays, the camera normally would’nt follow that, so i want it to follow it, but i want it so i can freely move my camera at any direction too.

Thanks!

1 Like

So you just want to attach the camera to the players head? While still being able to control the said camera?
My best bet would be to Inside a script read the head cframe and then just offseting the cameras cframe by it by adding both together, so it acts as if the camera is parented to the head.

how could i do that? sorry for asking, im kinda new with this hehe

LocalScript inside StarterCharacterScripts

--Services
local RunService = game:GetService("RunService")
local InputService = game:GetService("UserInputService")

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
Humanoid.AutoRotate = false

local CurrentCamera = workspace.Camera
CurrentCamera.CameraType = Enum.CameraType.Scriptable

local Head = Character:FindFirstChild("Head")

--Variables
local CameraRotation = Vector2.new(0,0) -- Stores Rotation of Camera
local RotationSpeed = Vector2.new(1,1) -- Defines Sensitivity of Camera

InputService.InputChanged:Connect(function(Input)
	if Input.UserInputType == Enum.UserInputType.MouseMovement then
		CameraRotation += Vector2.new(Input.Delta.X * -1,Input.Delta.Y * -1) * RotationSpeed
	end
end)

RunService.RenderStepped:Connect(function()
	InputService.MouseBehavior = Enum.MouseBehavior.LockCenter
	
	local HorizontalAngle = math.rad(CameraRotation.X)
	local VerticalAngle = math.rad(CameraRotation.Y)
	
	CurrentCamera.CFrame =  Head.CFrame * CFrame.fromEulerAnglesYXZ(VerticalAngle,HorizontalAngle,0)
end)

Closest thing to what you want that i could write in a rush.

1 Like

Tysm! It worked:D


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