How do I make the Players character look up and down when the player does?
You can take the angle of the camera and apply that to the neck joint in the players head.
I have scripted this before, and i dont care about the code being leaked or anything becuase i modified a pre-existing script.
So here it is:
(Local Script inside StarterCharacterScripts)
local RunService = game:GetService('RunService')
local Event = script:WaitForChild('LookEvent')
local Player = game.Players.LocalPlayer
local Camera = workspace:WaitForChild('Camera')
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild('Head')
local Humanoid = Character:WaitForChild('Humanoid')
local Torso
local Neck
if Humanoid.RigType == Enum.HumanoidRigType.R6 then
Torso = Character:WaitForChild('Torso')
Neck = Torso:WaitForChild('Neck')
else
Torso = Character:WaitForChild('UpperTorso')
Neck = Character:WaitForChild('Head'):WaitForChild('Neck')
end
local RootPart = Character:WaitForChild('HumanoidRootPart')
local Mouse = Player:GetMouse()
local Ang = CFrame.Angles
local aSin = math.asin
local aTan = math.atan
local NeckOrgnC0 = Neck.C0
local HeadHorFactor = 0.8
local HeadVertFactor = 0.7
local UpdateSpeed = 0.5
while task.wait(0.0125) do
local CameraCFrame = Camera.CoordinateFrame
Event:FireServer(CameraCFrame, HeadHorFactor, HeadVertFactor, UpdateSpeed)
end
(Script inside of the Local Script)
local Event = script.Parent:WaitForChild('LookEvent')
local Ang = CFrame.Angles
local aSin = math.asin
local aTan = math.atan
local Character = script.Parent.Parent
local Head = Character:WaitForChild('Head')
local Humanoid = Character:WaitForChild('Humanoid')
local Torso
local Neck
if Humanoid.RigType == Enum.HumanoidRigType.R6 then
Torso = Character:WaitForChild('Torso')
Neck = Torso:WaitForChild('Neck')
else
Torso = Character:WaitForChild('UpperTorso')
Neck = Character:WaitForChild('Head'):WaitForChild('Neck')
end
local RootPart = Character:WaitForChild('HumanoidRootPart')
local NeckOrgnC0 = Neck.C0
Event.OnServerEvent:Connect(function(Player, CameraCFrame, HeadHorFactor, HeadVertFactor, UpdateSpeed)
if Humanoid.RigType == Enum.HumanoidRigType.R6 then
local HeadPosition = Head.CFrame.Position
local TorsoLookVector = Torso.CFrame.lookVector
local Dist = (Head.CFrame.Position-CameraCFrame.Position).magnitude
local Diff = Head.CFrame.Y-CameraCFrame.Y
Neck.C0 = Neck.C0:Lerp(NeckOrgnC0*Ang(-(aSin(Diff/Dist)*HeadVertFactor), 0, -(((HeadPosition-CameraCFrame.Position).Unit):Cross(TorsoLookVector)).Y*HeadHorFactor),UpdateSpeed/2)
elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
local HeadPosition = Head.CFrame.Position
local TorsoLookVector = Torso.CFrame.lookVector
local Dist = (Head.CFrame.Position-CameraCFrame.Position).magnitude
local Diff = Head.CFrame.Y-CameraCFrame.Y
Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aSin(Diff/Dist)*HeadVertFactor), -(((HeadPosition-CameraCFrame.Position).Unit):Cross(TorsoLookVector)).Y*HeadHorFactor, 0), UpdateSpeed/2)
end
end)
(How it should be set up)
This works for both R15 and R6, however the R15 version wont rotate the torso.
It also only follows the Camera.LookVector
instead of the mouse, as i modified the script primarily for my shooter game.
How would I animate the torso on R15?
Alright, i just updated the script to make the torso move aswell, but to make things easier ive made the scripts into a model, which you can just easily import into your game.
Model link: Head Follows Camera - Roblox
If you want to copy-paste the scripts though, theyre nearly the exact same. Heres the updated scripts:
(LocalScript parented to StarterCharacterScripts)
local RunService = game:GetService('RunService')
local Event = script:WaitForChild('LookEvent')
local Player = game.Players.LocalPlayer
local Camera = workspace:WaitForChild('Camera')
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild('Head')
local Humanoid = Character:WaitForChild('Humanoid')
local Torso
local Neck
if Humanoid.RigType == Enum.HumanoidRigType.R6 then
Torso = Character:WaitForChild('Torso')
Neck = Torso:WaitForChild('Neck')
else
Torso = Character:WaitForChild('UpperTorso')
Neck = Character:WaitForChild('Head'):WaitForChild('Neck')
end
local RootPart = Character:WaitForChild('HumanoidRootPart')
local Mouse = Player:GetMouse()
local Ang = CFrame.Angles
local aSin = math.asin
local aTan = math.atan
local NeckOrgnC0 = Neck.C0
local HeadHorFactor = 0.8
local HeadVertFactor = 0.7
local TorsoHorFactor = 0.8
local TorsoVertFactor = 0.7
local UpdateSpeed = 0.5
while task.wait(0.0125) do
local CameraCFrame = Camera.CoordinateFrame
Event:FireServer(CameraCFrame, HeadHorFactor, HeadVertFactor, UpdateSpeed, TorsoHorFactor, TorsoVertFactor)
end
(Script parented to LocalScript)
local Event = script.Parent:WaitForChild('LookEvent')
local Ang = CFrame.Angles
local aSin = math.asin
local aTan = math.atan
local Character = script.Parent.Parent
local Head = Character:WaitForChild('Head')
local Humanoid = Character:WaitForChild('Humanoid')
local Torso
local Waist
local Neck
if Humanoid.RigType == Enum.HumanoidRigType.R6 then
Torso = Character:WaitForChild('Torso')
Neck = Torso:WaitForChild('Neck')
else
Torso = Character:WaitForChild('UpperTorso')
Neck = Character:WaitForChild('Head'):WaitForChild('Neck')
Waist = Torso:WaitForChild('Waist')
end
local RootPart = Character:WaitForChild('HumanoidRootPart')
local NeckOrgnC0 = Neck.C0
local WaistOrgnC0 = Waist.C0
Event.OnServerEvent:Connect(function(Player, CameraCFrame, HeadHorFactor, HeadVertFactor, UpdateSpeed, TorsoHorFactor, TorsoVertFactor)
if Humanoid.RigType == Enum.HumanoidRigType.R6 then
local HeadPosition = Head.CFrame.Position
local TorsoLookVector = Torso.CFrame.lookVector
local Dist = (Head.CFrame.Position-CameraCFrame.Position).magnitude
local Diff = Head.CFrame.Y-CameraCFrame.Y
Neck.C0 = Neck.C0:Lerp(NeckOrgnC0*Ang(-(aSin(Diff/Dist)*HeadVertFactor), 0, -(((HeadPosition-CameraCFrame.Position).Unit):Cross(TorsoLookVector)).Y*HeadHorFactor),UpdateSpeed/2)
elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
local HeadPosition = Head.CFrame.Position
local TorsoPosition = Torso.CFrame.Position
local TorsoLookVector = Torso.CFrame.lookVector
local Dist = (Head.CFrame.Position-CameraCFrame.Position).magnitude
local Diff = Head.CFrame.Y-CameraCFrame.Y
Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aSin(Diff/Dist)*(HeadVertFactor/2)), -(((HeadPosition-CameraCFrame.Position).Unit):Cross(TorsoLookVector)).Y*(HeadHorFactor/2), 0), UpdateSpeed/2)
Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang((aSin(Diff/Dist)*(TorsoVertFactor/2)), -(((TorsoPosition-CameraCFrame.Position).Unit):Cross(TorsoLookVector)).Y*(TorsoHorFactor/2), 0), UpdateSpeed/2)
end
end)
Other than the slight script modifications, everything is the exact same.
this solution is so bad it completely breaks in first person if you are actually looking front and walking to the side, the script thinks your looking to the side???