Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make players heads bob in First Person?

Asked by
Yirny 30
8 years ago

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

Log in to vote
2
Answered by 8 years ago

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

0
Sorry I was away for a second lol. Thanks anyways for helping me and replying quickly! Yirny 30 — 8y
0
Use RenderStepped for it the be the smoothest. User#11440 120 — 8y
Ad
Log in to vote
0
Answered by
IdoWhy 0
3 years ago
Edited 3 years ago

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 :)

Answer this question