- I am trying to make a grapple hook physics based
2.I have made the grapple hook but I can’t figure out (even by looking in the dev forum) how to make it swing, video of what i want it to look like: Roblox Grappling Hook - YouTube
- I have tried messing with the settings and I cant figure out how to make it work
I have tried to make it a rope, changed some settings in the scripts but I can’t figure out how I can make it swing smooth. I want to make it for a parkour game
If someone can help me figure out how to make it work that would really help.
This is what I have right now:
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local tool = script.Parent
local base = tool:WaitForChild("Base")
local spring = base.Spring
local hook = tool:WaitForChild("Hook")
local hookWeld = hook.HookWeld
local hookReference = tool:WaitForChild("HookReference")
local messageEvent = script:WaitForChild("MessageEvent")
local activated = script:WaitForChild("Activated")
--ONLY CLIENT
local player = nil
local mouse = nil
local currentTween = nil
local GrappleGun = {}
local function toggleHumanoidGrappleState(active)
local humanoid = player.Character and player.Character:FindFirstChild("Humanoid")
if humanoid then
if active then
else
end
end
end
local function clientInit()
player = Players.LocalPlayer
mouse = player:GetMouse()
mouse.TargetFilter = player.Character
tool.Activated:Connect(function()
if not GrappleGun.IsActivated() and mouse.Target then
messageEvent:FireServer(true, mouse.Hit.Position)
toggleHumanoidGrappleState(true)
end
end)
tool.Deactivated:Connect(function()
messageEvent:FireServer(false)
toggleHumanoidGrappleState(false)
end)
tool.Unequipped:Connect(function()
messageEvent:FireServer(false)
toggleHumanoidGrappleState(false)
end)
end
local function serverInit()
messageEvent.OnServerEvent:Connect(function(player, _activated, targetPosition)
activated.Value = _activated
if GrappleGun.IsActivated() then
GrappleGun.Fire(targetPosition)
else
GrappleGun.Reset()
end
end)
end
local function init()
if RunService:IsClient() then
clientInit()
elseif RunService:IsServer() then
serverInit()
end
end
function GrappleGun.IsActivated()
return activated.Value
end
function GrappleGun.Fire(targetPosition)
local initalPos = hookReference.Position
local distance = (targetPosition - initalPos).Magnitude
hookWeld.Enabled = false
hook.Anchored = true
wait()
hook.Position = targetPosition
spring.FreeLength = distance
local info = TweenInfo.new(distance/100, Enum.EasingStyle.Linear)
local tween = TweenService:Create(spring, info, {FreeLength = 75})
tween:Play()
currentTween = tween
end
function GrappleGun.Reset()
if currentTween then
currentTween:Cancel()
end
hook.CFrame = hookReference.CFrame
hookWeld.Enabled = true
hook.Anchored = false
spring.FreeLength = 1
end
init()
return GrappleGun