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

How would I make the player's arms and head follow the mouse? [R15]

Asked by
gitrog 326 Moderation Voter
6 years ago

So, I've been playing around with trying a ton of different animations for each position, but this seems very inefficient. I want to be able to move the player's arms and head to follow the mouse, while also having the arms play an animation (holding a gun.) How would I do this more efficiently?

0
I'm not sure, sorry. Lightning_Mark 0 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

well, here is a script, place it in starterGUI in a LocalScript.



wait() local Ang = CFrame.Angles local aSin = math.asin local aTan = math.atan local Cam = game.Workspace.CurrentCamera local Plr = game.Players.LocalPlayer local Mouse = Plr:GetMouse() local Body = Plr.Character or Plr.CharacterAdded:wait() local Head = Body:WaitForChild("Head") local Hum = Body:WaitForChild("Humanoid") local Core = Body:WaitForChild("HumanoidRootPart") local IsR6 = (Hum.RigType.Value==0) local Trso = (IsR6 and Body:WaitForChild("Torso")) or Body:WaitForChild("UpperTorso") local Neck = (IsR6 and Trso:WaitForChild("Neck")) or Head:WaitForChild("Neck") local Waist = (not IsR6 and Trso:WaitForChild("Waist")) local MseGuide = false local TurnCharacterToMouse = false local HeadHorFactor = 1 local HeadVertFactor = 0.6 local BodyHorFactor = 0.5 local BodyVertFactor = 0.4 local UpdateSpeed = 0.5 local NeckOrgnC0 = Neck.C0 local WaistOrgnC0 = (not IsR6 and Waist.C0) Neck.MaxVelocity = 1/3 if TurnCharacterToMouse == true then MseGuide = true HeadHorFactor = 0 BodyHorFactor = 0 end game:GetService("RunService").RenderStepped:Connect(function() local CamCF = Cam.CoordinateFrame if ((IsR6 and Body["Torso"]) or Body["UpperTorso"])~=nil and Body["Head"]~=nil then local TrsoLV = Trso.CFrame.lookVector local HdPos = Head.CFrame.p if IsR6 and Neck or Neck and Waist then if Cam.CameraSubject:IsDescendantOf(Body) or Cam.CameraSubject:IsDescendantOf(Plr) then local Dist = nil; local Diff = nil; if not MseGuide then Dist = (Head.CFrame.p-CamCF.p).magnitude Diff = Head.CFrame.Y-CamCF.Y if not IsR6 then Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aSin(Diff/Dist)*HeadVertFactor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*HeadHorFactor, 0), UpdateSpeed/2) Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang((aSin(Diff/Dist)*BodyVertFactor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*BodyHorFactor, 0), UpdateSpeed/2) else Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang(-(aSin(Diff/Dist)*HeadVertFactor), 0, -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y*HeadHorFactor),UpdateSpeed/2) end else local Point = Mouse.Hit.p Dist = (Head.CFrame.p-Point).magnitude Diff = Head.CFrame.Y-Point.Y if not IsR6 then Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang(-(aTan(Diff/Dist)*HeadVertFactor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*HeadHorFactor, 0), UpdateSpeed/2) Waist.C0 = Waist.C0:lerp(WaistOrgnC0*Ang(-(aTan(Diff/Dist)*BodyVertFactor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*BodyHorFactor, 0), UpdateSpeed/2) else Neck.C0 = Neck.C0:lerp(NeckOrgnC0*Ang((aTan(Diff/Dist)*HeadVertFactor), 0, (((HdPos-Point).Unit):Cross(TrsoLV)).Y*HeadHorFactor), UpdateSpeed/2) end end end end end if TurnCharacterToMouse == true then Hum.AutoRotate = false Core.CFrame = Core.CFrame:lerp(CFrame.new(Core.Position, Vector3.new(Mouse.Hit.p.x, Core.Position.Y, Mouse.Hit.p.z)), UpdateSpeed / 2) else Hum.AutoRotate = true end end)
0
i use dis Nonglolprogames -19 — 6y
0
This only works locally, is there a way to make it work both on the server side and locally? gitrog 326 — 6y
0
lol idk Nonglolprogames -19 — 6y
0
I'm sorry but this is very clearly a free script, and I didn't ask for a script to do this, especially one that doesn't even do what I asked or what I need it to do, I wanted to know where I'd start in scripting it. gitrog 326 — 6y
Ad

Answer this question