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

How can I make the FPS arms stay with the camera?

Asked by 7 years ago

So, I'm making a gun for an FPS. I already have the script for showing the FPS arms, and animations, etc. I'm just having trouble with having the arms follow the camera. Basically, I want the torso to move to the Y point of the camera but I don't want the legs to move with the torso. I have this code here:

mouse.Move:connect(function()
        mouse.TargetFilter = game.Workspace
        torso.CFrame = CFrame.new(torso.Position, Vector3.new(mouse.Hit.p.X,              mouse.Hit.p.Y, mouse.Hit.p.Z))
end)

It works decently, but if your arms touch the ground then it like flings you and makes you fall. Also, the entire body moves; like, the legs also float with the torso. I want the legs to stay flat on the ground, and only have the torso move up and down on the Y axis according to the Y of the mouse. I was thinking of making the head move with the Y and welding the arms to the head, but I'm not sure to do that. Could anyone help me please? Thanks!

0
I think the flinging problem can be solved by setting CanCollide of the arms to false? HelloPeople0004 2 — 7y
0
Set the arms CanCollide property to false, also, you can use CFrame.new(torso.Position, mouse.Hit.p) instead of your whole vector3 stuff. The reason your legs move is because you set the CFrame of the torso. set the CFrame of the welds inside the torso instead. RubenKan 3615 — 7y

1 answer

Log in to vote
0
Answered by 4 years ago

for FPS I prefer to use R6 real arms this is my local script:

plr = game.Players.LocalPlayer;
repeat wait() until plr.Character
char = plr.Character
m = plr:GetMouse()
game["Run Service"].RenderStepped:connect(function()
local c = game.Workspace.CurrentCamera

char.HumanoidRootPart["RootJoint"].C0 = CFrame.new(0,0,0) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y) + 1.55,3.15,0)

    char.Humanoid.CameraOffset = (char.HumanoidRootPart.CFrame+Vector3.new(0,0,0)):pointToObjectSpace(char.Head.CFrame.p + Vector3.new(0,-1.46,0))

end)
Ad

Answer this question