From efec7163796560f262c1d3b268d3fecf641f8952 Mon Sep 17 00:00:00 2001 From: JJRcop Date: Tue, 1 Aug 2017 17:14:23 -0400 Subject: [PATCH] grapple hook fix, add velocity inheritance Fixes grapple hook to work with HumanoidRootPart Now dynamically based off of Workspace.Gravity Projectile inherits Velocity of Handle when fired --- Items/Gear/30393548.rbxmx | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/Items/Gear/30393548.rbxmx b/Items/Gear/30393548.rbxmx index 2b77acbf..50555e10 100755 --- a/Items/Gear/30393548.rbxmx +++ b/Items/Gear/30393548.rbxmx @@ -444,7 +444,6 @@ for i, v in pairs({Sounds.Connect, Sounds.Hit}) do Sound.Parent = BaseGrappleHook end -Gravity = 196.20 Rate = (1 / 60) MaxDistance = 200 @@ -527,7 +526,7 @@ function DisconnectGrappleHook(KeepBodyObjects) end end if CheckIfAlive() and not KeepBodyObjects then - for i, v in pairs(Torso:GetChildren()) do + for i, v in pairs(HumanoidRootPart:GetChildren()) do if string.find(string.lower(v.ClassName), string.lower("Body")) then v:Destroy() end @@ -542,7 +541,7 @@ function TryToConnect() DisconnectGrappleHook() return end - local DistanceApart = (Torso.Position - GrappleHook.Position).Magnitude + local DistanceApart = (HumanoidRootPart.Position - GrappleHook.Position).Magnitude if DistanceApart > MaxDistance then DisconnectGrappleHook() return @@ -591,7 +590,7 @@ function TryToConnect() ConnectSound:Play() end - for i, v in pairs(Torso:GetChildren()) do + for i, v in pairs(HumanoidRootPart:GetChildren()) do if string.find(string.lower(v.ClassName), string.lower("Body")) then v:Destroy() end @@ -605,13 +604,13 @@ function TryToConnect() P = 3000, maxForce = Vector3.new(1000000, 1000000, 1000000), position = TargetPosition, - Parent = Torso, + Parent = HumanoidRootPart, } local BodyGyro = Create("BodyGyro"){ maxTorque = Vector3.new(math.huge, math.huge, math.huge), - cframe = CFrame.new(Torso.Position, Vector3.new(GrappleCFrame.p.X, Torso.Position.Y, GrappleCFrame.p.Z)), - Parent = Torso, + cframe = CFrame.new(HumanoidRootPart.Position, Vector3.new(GrappleCFrame.p.X, HumanoidRootPart.Position.Y, GrappleCFrame.p.Z)), + Parent = HumanoidRootPart, } Spawn(function() @@ -628,8 +627,12 @@ function CheckIfGrappleHookAlive() return (((GrappleHook and GrappleHook.Parent --[[and Rope and Rope.Parent]]) and true) or false) end +function CheckIfForceAlive() + return (((Force and Force.Parent and Force.Parent == GrappleHook) and true) or falce) +end + function CheckIfAlive() - return (((Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Torso and Torso.Parent and Player and Player.Parent) and true) or false) + return (((Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and HumanoidRootPart and HumanoidRootPart.Parent and Player and Player.Parent) and true) or false) end function Activated() @@ -658,10 +661,13 @@ function Activated() Mesh.MeshId = Meshes.Grapple GrappleHook = BaseGrappleHook:Clone() GrappleHook.CFrame = (CFrame.new((Handle.Position + (MousePosition - Handle.Position).Unit * 5), MousePosition) * CFrame.Angles(0, 0, 0)) - local Weight = 70 - GrappleHook.Velocity = (GrappleHook.CFrame.lookVector * Weight) - local Force = Create("BodyForce"){ - force = Vector3.new(0, Weight, 0), + local Speed = 20 + local Fall = 7 + local Mass = GrappleHook:GetMass() + Gravity = Workspace.Gravity + GrappleHook.Velocity = (GrappleHook.CFrame.lookVector * (Speed / Mass)) + Handle.Velocity + Force = Create("BodyForce"){ + force = Vector3.new(0, ((Gravity * Mass) - Fall), 0), Parent = GrappleHook, } GrappleHook.Parent = Tool @@ -675,6 +681,9 @@ function Activated() Spawn(function() while CheckIfGrappleHookAlive() and ToolEquipped and CheckIfAlive() do AdjustRope() + if Workspace.Gravity ~= Gravity and CheckIfForceAlive() then + Force.force = Vector3.new(0, ((Workspace.Gravity * GrappleHook:GetMass()) - Fall), 0) + end Spawn(function() if not Connected then TryToConnect() @@ -690,7 +699,7 @@ end function Equipped(Mouse) Character = Tool.Parent Humanoid = Character:FindFirstChild("Humanoid") - Torso = Character:FindFirstChild("Torso") + HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart") Player = Players:GetPlayerFromCharacter(Character) if not CheckIfAlive() then return