How to make player's camera follow crouch

Hello DevForum! I made a crouch script from a YouTube tutorial, but the problem is, that my game is first person, and I want the camera to go down with the animation crouch. How can I do it?!

Script:

local uis = game:GetService("UserInputService")


local humanoid = script.Parent:WaitForChild("Humanoid")


local animationIdle = humanoid:LoadAnimation(script:WaitForChild("CrouchIdle"))
local animationMoving = humanoid:LoadAnimation(script:WaitForChild("CrouchMoving"))


local crouching = false


uis.InputBegan:Connect(function(inp, processed)


	if processed  then return end


	if inp.KeyCode == Enum.KeyCode.LeftControl then

		crouching = not crouching
	end
end)


game:GetService("RunService").Heartbeat:Connect(function()

	script.Parent.HumanoidRootPart.CanCollide = false


	if crouching then


		humanoid.WalkSpeed = 7

		animationIdle:Play()


		if humanoid.MoveDirection.Magnitude > 0 then

			if not animationMoving.IsPlaying then animationMoving:Play() end


		else

			animationMoving:Stop()
		end


	else

		animationIdle:Stop()
		animationMoving:Stop()

		humanoid.WalkSpeed = 10
	end
end)
3 Likes

You can get the offset between the torso and head, then set that to the humanoid’s CameraOffset to achieve this.

local RNS = game:GetService("RunService")
local PS = game:GetService("Players")

local player = PS.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local HRP = char:WaitForChild("HumanoidRootPart")
local head = char:WaitForChild("Head")

RNS.RenderStepped:Connect(function()
	local objectSpace = (HRP.CFrame + Vector3.new(0, 1.5, 0)):ToObjectSpace(head.CFrame)
	
	hum.CameraOffset = objectSpace.Position
end)

6 Likes

Would I have to make this in a seperate script?

Edit:
Never mind figured it out thank you.

1 Like