Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you make the camera move with a character's head? (ASKING QUESTION AGAIN)

Here was what I had tried:

player = game.Players.LocalPlayer
char = player.Character
camera = workspace.CurrentCamera

game:GetService("RunService").RenderStepped:connect(function()
camera.CFrame = camera.CFrame + Vector3.new(0,char.Head.Position.y,0)
end)

What I was trying to do was make the camera move horizontally with the head.

EX: Character crouches, camera moves down with character's head

1 answer

repeat wait() until script.Parent.Parent --eh this part could be alot better but cba to change
repeat wait() until script.Parent.Parent.Character
player = script.Parent.Parent
char = player.Character
camera = workspace.CurrentCamera

local IsStanding = true
local IsCrouching = false
local IsProne = false
game:GetService("RunService").RenderStepped:Connect(function()
	if IsStanding then
		camera.CFrame = camera.CFrame + Vector3.new(0,(char.Head.Position.y-4.8),0) -- (-4.8) is accurate since a character is 5 studs and 4.8 is eye level
	elseif IsCrouching then
		camera.CFrame = camera.CFrame + Vector3.new(0,(char.Head.Position.y-6),0)
	elseif IsProne then
		camera.CFrame = camera.CFrame + Vector3.new(0,(char.Head.Position.y-7.8),0)		
	end
end)

This code does work (bit basic) although you do have to have a bit of code that changes the bool values. --you may have to change them all to -4.8 since it is using char.Head.Position.y

The code needs to be local script and should be a decendent (child/be in) StarterPlayerScripts which is found in StarterPlayer.

2 comments

0

This is the same problem my current script has encountered.

0

Did you copy ot exactly and put the local script in the right place because it works when I tested it

This discussion is preserved as it was. New answers, comments, and votes are closed.