Hello! I’m working on a grapple hook system, where if the player presses G they grapple to the position where the mouse is. However, there is some very weird and buggy behavior. What I want to achieve is similar to the system in this game: https://www.youtube.com/watch?v=RDfObDKhteA (Timestamp = 0:16)
I’ve tried changing the rope constraint position, attachting the rope to different body parts, but it just doesn’t seem to work.
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local mouse = player:GetMouse()
local attachment0 = nil
local attachment1 = nil
local rope = nil
local mousePart = nil
local grappling = false
UIS.InputBegan:Connect(function(input, gPE)
if gPE then return end
if input.KeyCode == Enum.KeyCode.G then
print("Grapple")
grappling = true
rope = Instance.new("RopeConstraint")
attachment0 = Instance.new("Attachment")
attachment1 = Instance.new("Attachment")
rope.Parent = player.Character
rope.Thickness = 1
rope.Visible = true
rope.Color = BrickColor.new("Really black")
rope.Attachment0 = attachment0
rope.Attachment1 = attachment1
attachment0.Parent = player.Character.HumanoidRootPart
mousePart = Instance.new("Part", workspace)
mousePart.Transparency = 1
mousePart.CanCollide = false
mousePart.Name = "MousePart"
mousePart.Size = Vector3.new(0.1, 0.1, 0.1)
mousePart.Position = mouse.Hit.Position
attachment1.Parent = mousePart
rope.Length = 10
attachment0.Position = player.Character.HumanoidRootPart.Position
attachment1.Position = mousePart.Position
end
end)
UIS.InputEnded:Connect(function(input, gPE)
if gPE then return end
if input.KeyCode == Enum.KeyCode.G then
grappling = false
if rope ~= nil then
rope:Destroy()
end
if attachment0 ~= nil then
attachment0:Destroy()
end
if attachment1 ~= nil then
attachment1:Destroy()
end
if mousePart ~= nil then
mousePart:Destroy()
end
end
end)
What could be causing this issue? Do you know any way I could fix this?
It looks like the rope is created behind the player and connecting to other objects than you’d like.
I don’t see where you change the attachment’s position as an example. That could be your problem.
At 0:03 in your gif you can see how the rope is created just in front of the camera and I would guess it’s connecting to the floor, thereby dragging you to the floor.
I actually wanted the mousePart to later be a small indicator showing the attachment. And I just checked and saw that for some reason, attachment0 gets moved somewhere far away from the HRP, even though I clearly position it in the HRP. I can try playing around with the restitution though.
Try setting the attachment’s Positions before you set the rope’s attachments. It might be that the rope won’t recognize the change in position after it’s been set.