Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Commit

Permalink
grapple hook fix, add velocity inheritance
Browse files Browse the repository at this point in the history
Fixes grapple hook to work with HumanoidRootPart
Now dynamically based off of Workspace.Gravity
Projectile inherits Velocity of Handle when fired
  • Loading branch information
JJRcop committed Aug 1, 2017
1 parent 0cbcb64 commit 73efb61
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions Items/Gear/30393548.rbxmx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit 73efb61

Please sign in to comment.