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

How do I make players heads bob in First Person?

I'm making a horror game and I want it to be as realistic as possible. I want to know how to make the camera look in front of the players head for realism and to make it bob.

2 answers

✓ Accepted answer

Of course you are setting up the camera for a player so you will use a LocalScript. However seeming difficult the method to create a head bobbing script is quite simple.

local cam = workspace.CurrentCamera -- Define CurrentCamera
local lp = game.Players.LocalPlayer
repeat wait() until lp.Character --Wait for character
local character = lp.Character

lp.CameraMode = "LockFirstPerson" --Force First Person Mode

while true do --Setup a while loop
	wait()
	cam.CFrame = character.Head.CFrame --This will set the the cameras CFrame to the character's head
end

If you want to learn more just read up on these articles: http://wiki.roblox.com/index.php?title=Camera_manipulation http://wiki.roblox.com/index.php?title=API:Class/Camera

2 comments

0

Sorry I was away for a second lol. Thanks anyways for helping me and replying quickly!

0

Use RenderStepped for it the be the smoothest.

Hey ya, I've made a script, sorry for 4 years late lol

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Humanoid = workspace:WaitForChild(Player.Name).Humanoid
local Head = Humanoid.Parent.Head
local HumanoidRootPart = game.Workspace[Player.Name].HumanoidRootPart
local Mouse = Player:GetMouse()
while true do
	wait()
	Humanoid.CameraOffset = Head.Position - HumanoidRootPart.Position + Vector3.new(0, -1.5, -1)
end


Basically, it changes the humanoid offset to the head position minus humanoid root part position, and then the camera is close to the head, you can change the position how you'd like to with just simply changing the Vector3 value. No problem :)

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