Hi, i have a quite a problem with a grappling hook script that i found on youtube and decided to modify it but there’s quite an issue that i can’t resolve.
Here’s how it works without interacting with the issue:
https://gyazo.com/bd8853b0d0bf4cf999807bcc8795f246
Now here’s the issue:
https://gyazo.com/a6273eea76a18c1adb45888ca0babf6b
As you can clearly see the grappling hook has terrible damping/stiffness and it on one hand makes it really satisfying to swing with but on the other hand its also a detriment since it slows down the player when doing what ive shown on the video, so grappling from above and aiming at the ground can kill all of your momentum.
Now i’ve tried fixing it for a long time and the best i could do is make some crazy caluclations that do not make sense but somehow kinda work(not really) but i hope someone here has a formula for this kind of thing so i can get rid of this nonsense of a calculation also here’s the code for the grappling hook:
local plr = game.Players.LocalPlayer
local head = plr.Character:FindFirstChild("Head")
local rightarm = plr.Character:FindFirstChild("Right Arm")
local hum = plr.Character:FindFirstChild("Humanoid")
local hrp = plr.Character:FindFirstChild("HumanoidRootPart")
local Mouse = plr:GetMouse()
local Debounce = false
local mouseDown = false
local Max_Distance = 150
hum:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
local impact = Instance.new("Sound")
impact.SoundId = "rbxassetid://0"
impact.Parent = script.Parent
impact.Volume = 2
local pull = Instance.new("Sound")
pull.SoundId = "rbxassetid://0"
pull.Parent = script.Parent
pull.Volume = 5
local grapprel = Instance.new("Sound")
grapprel.SoundId = "rbxassetid://0"
grapprel.Parent = script.Parent
grapprel.Volume = 3
local pulling = Instance.new("Animation")
pulling.AnimationId = "http://www.roblox.com/asset/?id=0"
local pulling = hum:LoadAnimation(pulling)
local function distance_between_vectors(u, v)
local difference = u - v
local distance = difference.Magnitude
distance = math.floor(distance / 1 + 0.5) * 1
return distance
end
local function Attachment(method, parent)
if method == "Create" then
local Attachement = Instance.new("Attachment")
Attachement.Parent = parent
else
parent.Attachment:Destroy()
end
end
Mouse.Button1Up:Connect(function()
mouseDown = false
end)
Mouse.Button1Down:Connect(function()
mouseDown = true
if Debounce == false then
Debounce = true
local HitPosition = Mouse.Hit.p
local distance = distance_between_vectors(HitPosition, hrp.Position, rightarm.Position)
if distance <= Max_Distance then
grapprel:Play()
pulling:Play()
pulling:AdjustSpeed(1.8)
task.wait(0.15)
pull:Play()
impact:Play()
local NewPart = Instance.new("Part")
NewPart.Anchored = true
NewPart.Parent = game.Workspace
NewPart.Position = HitPosition
NewPart.Transparency = 1
local NewPart2 = Instance.new("Part")
NewPart2.Anchored = true
NewPart2.Parent = game.Workspace
NewPart2.Position = HitPosition
NewPart2.Transparency = 1
Attachment("Create", NewPart)
Attachment("Create", hrp)
Attachment("Create", NewPart2)
Attachment("Create", rightarm)
local spring = Instance.new("SpringConstraint")
local beam = Instance.new("Beam")
beam.Parent = workspace
beam.Attachment0 = NewPart2.Attachment
beam.Attachment1 = rightarm.Attachment
beam.TextureLength = distance / 2
spring.Parent = NewPart
spring.Attachment0 = NewPart.Attachment
spring.Attachment1 = hrp.Attachment
spring.MaxForce = 10000000
local lenghtspring = spring.FreeLength
lenghtspring = distance/240
spring.Stiffness = lenghtspring*215000/distance
spring.Damping = lenghtspring*215000/distance
spring.Color = BrickColor.new("Institutional white")
spring.Visible = false
while mouseDown == true do
wait()
end
pulling:Stop()
Attachment("Destroy", NewPart)
Attachment("Destroy", hrp)
Attachment("Destroy", NewPart2)
Attachment("Destroy", rightarm)
NewPart.SpringConstraint:Destroy()
beam:Destroy()
NewPart2:Destroy()
NewPart:Destroy()
end
Debounce = false
end
end)