Hello, I’m making an FPS game and I want to know how I can make the player’s body look up when your camera looks up and looks down when your camera looks down? Arsenal has this feature, I don’t know what it’s called though.
1 Like
You can set your head’s CFrame LookVector to Camera’s LookVector I suppose.
I do not really know how that would work out since I do not have access to Studio right now,you can try it out though -
-- localscript
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local camera = workspace.CurrentCamera
local runService = game:GetService("RunService")
runService.Heartbeat:Connect(function(dt)
head.CFrame = CFrame.lookat(head.Position,camera.CFrame.LookVector)
end)
2 Likes
Thanks for the answer, I actually found a solution:
local Look, Origin = workspace.CurrentCamera.CFrame, Character.HumanoidRootPart.CFrame
Look = Look:ToWorldSpace(CFrame.new(0, 1.5, 0))
local Waist = Character:WaitForChild("UpperTorso"):WaitForChild("Waist")
local X, Y, Z = Look:ToEulerAnglesXYZ()
local RX, RY, RZ = Origin:ToEulerAnglesXYZ()
X = math.clamp(X, -72, 72)
local NewLook = CFrame.Angles(X, Y, Z)
local NewOrigin = CFrame.Angles(RX, RY, RZ)
NewLook = NewOrigin:ToObjectSpace(NewLook)
Waist.C0 = Waist.C0:lerp(CFrame.new(Waist.C0.Position) * NewLook, 1)
1 Like
@Zohair_028 However, the original post for this script uses a remote event to update the player character in the server because it’s only a client-sided script. The remote event is being fired inside a RunService.RenderStepped
, which is I think not a good idea especially if you have lots of players in one server. Is there a alternative way to make the changes also show in other clients / in the server?