I’m making a grappling hook and I’ve made it so jumping removes the rope and the goal was to fling you, but it wont work. Any ideas/help?
Btw, It does do what I want it to do, but you have to go really fast for it to actually do it
How is the grappling hook logic implemented? (i.e: how does it move the player?)
A rope is attached to a part and attached to the handle of the grappling hook, then it shortens the length of the rope. (the part is anchored so it grabs you and not moves with you)
Ah makes sense; If you remove the hook then there’s nothing pulling the player.
To retain the momentum, you would need to apply a force in the direction of the player’s movement once the player jumps or when spacebar is pressed.
Do you need help with the code implementation?
maybe, I may have found a fix, but I haven’t tried it yet. I’ll get back to you if I cant figure it out.
Ok yeah, I didn’t work. Could you help me?
Yeah could you reply with any scripts/localscripts that you have, like maybe for the grappling hook?
Okay, here’s my script:
local TweenService = game:GetService("TweenService")
local canUse = true
local ropeIsPulling = false
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid") or script.Parent.Parent.Parent.Character:FindFirstChild("Humanoid")
local hpr = humanoid.Parent:FindFirstChild("HumanoidRootPart")
local handle = script.Parent.Handle
script.Parent.LocalScript.RemoteEvent.OnServerEvent:Connect(function(player, position, object, distance)
if canUse == true then
canUse = false
local hook = Instance.new("Part", script.Parent)
hook.Anchored = true
hook.Size = Vector3.new(1, 1, 1)
hook.CanCollide = false
hook.Transparency = 0
hook.BrickColor = BrickColor.new("New Yeller")
hook.CFrame = CFrame.lookAt(handle.Position, position)
local rope = Instance.new("RopeConstraint", script.Parent)
local att0 = Instance.new("Attachment", handle)
local att1 = Instance.new("Attachment", hook)
rope.Length = distance - 1
rope.Attachment0 = att0
rope.Attachment1 = att1
rope.Visible = true
local Speed = 200
local function GetTime(Distance, Speed)
local Time = Distance / Speed
return Time
end
local Time = GetTime(distance, Speed)
local function DestoryHook()
hook:Destroy()
rope:Destroy()
att0:Destroy()
att1:Destroy()
end
if object.Mass >= 100 or object.Anchored == true or object.Parent:FindFirstChild("Humanoid") then
local tweenInfo = TweenInfo.new(Time, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local tween = TweenService:Create(hook, tweenInfo, {Position = position})
tween:Play()
tween.Completed:Wait()
coroutine.wrap(function()
local bv = Instance.new("BodyVelocity", handle)
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.Velocity = Vector3.new(0, Time * distance + (distance / 1.2), 0)
wait(Time * 1.1)
bv:Destroy()
end)()
humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
if humanoid.Jump == true and ropeIsPulling == true then
ropeIsPulling = false
DestoryHook()
print(hpr.Velocity)
local bv = Instance.new("BodyVelocity", handle)
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.Velocity = hpr.Velocity
wait(Time * 1.1)
bv:Destroy()
end
end)
local ropetween = TweenService:Create(rope, TweenInfo.new(rope.Length * 0.015, Enum.EasingStyle.Linear), {Length = 0})
ropetween:Play()
ropeIsPulling = true
ropetween.Completed:Wait()
DestoryHook()
ropeIsPulling = false
task.wait(1)
canUse = true
else ------------------------------------------------------------------------------------------------------------------------------
local tweenInfo = TweenInfo.new(Time, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local tween = TweenService:Create(hook, tweenInfo, {Position = position})
tween:Play()
tween.Completed:Wait()
local grabtween = TweenService:Create(object, TweenInfo.new(rope.Length * 0.015, Enum.EasingStyle.Linear), {Position = handle.Position})
grabtween:Play()
ropeIsPulling = true
TweenService:Create(hook, TweenInfo.new(rope.Length * 0.015, Enum.EasingStyle.Linear), {Position = handle.Position}):Play()
TweenService:Create(rope, TweenInfo.new(rope.Length * 0.015, Enum.EasingStyle.Linear), {Length = 0}):Play()
humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
if humanoid.Jump == true and ropeIsPulling == true then
ropeIsPulling = false
DestoryHook()
grabtween:Cancel()
end
end)
grabtween.Completed:Wait()
DestoryHook()
ropeIsPulling = false
task.wait(1)
canUse = true
end
end
end)
Can you change the print statement to “applying force”. Then use the grappling hook, jump, then tell me if you see “applying force” in the output log?
seems to work, but the Y gets way to much power, and the X and the Z dont get enough. Know a way to fix that?
Nevermind, i found a way. Thank you so much!
Actually, it doesn’t really work… Sometimes it just does in a random direction and doesn’t detect the velocity that well.
after tinkering with some stuff, i found a decent solution! thanks
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.