I'm currently making a FPS game right now. Can somebody help me make a non-local script that makes both arms, tools, and the head follow the player's camera. I am decent at scripting but have a hard time comprehending trigonometry. Thank you for reading.
Put this code in a local script in starterpack. I don't think you can do it with non-local scripts. Hope this helps anyways.
01 | plr = game.Players.LocalPlayer; |
02 | repeat wait() until plr.Character |
03 | char = plr.Character |
04 | m = plr:GetMouse() |
05 | game [ "Run Service" ] .RenderStepped:connect( function () |
06 | local c = game.Workspace.CurrentCamera |
07 | char.Torso [ "Right Shoulder" ] .C 0 = CFrame.new( 1 , 0.5 , 0 ) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y), 1.55 , 0 ) |
08 | char.Torso [ "Left Shoulder" ] .C 0 = CFrame.new(- 1 , 0.5 , 0 ) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y),- 1.55 , 0 ) |
09 | char.Torso [ "Neck" ] .C 0 = CFrame.new( 0 , 1 , 0 ) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y) + 1.55 , 3.15 , 0 ) |
10 | end )`` |
`
my script is better for FPS: in R6
01 | plr = game.Players.LocalPlayer; -- local script |
02 | repeat wait() until plr.Character |
03 | char = plr.Character |
04 | m = plr:GetMouse() |
05 | game [ "Run Service" ] .RenderStepped:connect( function () |
06 | local c = game.Workspace.CurrentCamera |
07 |
08 | char.HumanoidRootPart [ "RootJoint" ] .C 0 = CFrame.new( 0 , 0 , 0 ) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y) + 1.55 , 3.15 , 0 ) |
09 |
10 | char.Humanoid.CameraOffset = (char.HumanoidRootPart.CFrame+Vector 3. new( 0 , 0 , 0 )):pointToObjectSpace(char.Head.CFrame.p + Vector 3. new( 0 ,- 1.46 , 0 )) |
11 |
12 | end ) |