I’m trying to make a grappling hook system, which works pretty well when there’s no interaction with moving objects, however I noticed if there is a moving object, it doesn’t follow it.
I’ve tried using Welds and WeldConstraints to follow the moving object, however it doesn’t work as nicely as I would have hoped. The Weld instance anchors the hook to the centre of the object, and the WeldConstraint doesn’t follow the object at all.
This has introduced a whole host of other issues such as the player not looking toward where the hook is going and flying around.
CastHook.Fire = function(player,side,pos,target)
local char = player.Character
local ODM = char.ODMGear
local Barrel = nil
local hook = nil
if side == "Left" then
if ODM.Propeller.LeftBarrel.Hook:FindFirstChild"retract" then return end
Barrel = ODM.Propeller.LeftBarrel
hook = Barrel.Hook
Barrel:SetAttribute("Engaged",true)
elseif side == "Right" then
if ODM.Propeller.RightBarrel.Hook:FindFirstChild"retract" then return end
Barrel = ODM.Propeller.RightBarrel
hook = Barrel.Hook
Barrel:SetAttribute("Engaged",true)
end
local t = 2*pos.Magnitude/2000
local info = TweenInfo.new(t,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0)
local tweenLength = TS:Create(Barrel.Wire,info,{Length = pos.Magnitude})
local tweenPosition =TS:Create(hook,info,{Position = pos})
sounds.ODMSounds:Play()
tweenLength:Play()
tweenPosition:Play()
hook.Anchored = true
tweenPosition.Completed:Wait()
sounds.GasApplied:Play()
local weld = Instance.new("WeldConstraint",hook); weld.Name = "Weld"; weld.Part0 = hook; weld.Part1 = target
hook.Anchored = false
local info_Speed = TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0.1)
Barrel.BarrelForce.Enabled = true
local speedTween = TS:Create(Barrel.BarrelForce,info,{VectorVelocity = Vector3.new(100,0,0)})
speedTween:Play()
accelerating = true
speedTween.Completed:Connect(function()
sounds.Reel:Play()
accelerating = false
end)
if not char.LowerTorso:FindFirstChild"AlignVertical" then
alignY = Instance.new("AlignOrientation")
alignY.Mode = Enum.OrientationAlignmentMode.OneAttachment
alignY.Parent = char.LowerTorso
alignY.Attachment0 = char.LowerTorso.WaistRigAttachment
alignY.Responsiveness = 5
alignY.Name = "AlignVertical"
end
if not char.LowerTorso:FindFirstChild"AlignLook" then
o = Instance.new("AlignOrientation")
o.Parent = char.LowerTorso
o.Mode = Enum.OrientationAlignmentMode.OneAttachment
o.Attachment0 = char.LowerTorso.WaistRigAttachment
o.AlignType = Enum.AlignType.PrimaryAxisLookAt
char.LowerTorso.WaistRigAttachment.Axis = Vector3.new(0,0,-1)
o.RigidityEnabled = true
o.ReactionTorqueEnabled = true
o.Responsiveness = 50
task.spawn(function() -- Trying to solve player not looking toward the hook, causing them to fly about
while Barrel:GetAttribute("Enabled") == true do
wait()
o.LookAtPosition = hook.Position
end
end)
o.Name = "AlignLook"
end
if not char.LowerTorso:FindFirstChild"VectorForce" then
f = Instance.new("VectorForce")
f.Parent = char.LowerTorso
f.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
f.Attachment0 = char.LowerTorso:WaitForChild("WaistRigAttachment")
f.Force = Vector3.new(0,game.Workspace.Gravity*char.PrimaryPart.AssemblyMass*0.8,0)
else end
end
I’ve reviewed other code which does exactly what I want it to do and integrated it into this function, however the problem doesn’t seem to solve itself. The hook mechanism works perfectly when no moving objects are involved.
The hooks following any moving objects is pretty integral to the gameplay, so any help at resolving this issue would be appreciated!