Weird grapple hook behavior

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)

My character spins and glitches out of the map when I use the grapple system. Issue: https://gyazo.com/704feb63cf3cf3d8ba203e2bc68313f2

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’m not the best at constraints, but I’m pretty sure this is where I change the attachments position.

Ah sorry, didn’t see that.

You could probably change:

 attachment1.Position = mousePart.Position

to

attachment1.Position = mouse.Hit.Position

As I don’t see the point of the mousePart instance other than it being a parent. And this would free up 6 lines of code.

Have you checked that the positions are alright?
Have you tried playing with the restitution of the rope?

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.

1 Like

image
Weird. I saw that the rope is somehow attached far away below the player. Also, changing the restitution doesn’t help.

What Y value are you getting on the player’s position?

134 On the Y value, baseplate is on 128, so it’s alright

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.

Hmm… I tried it, same result. Character gets flung off the baseplate and the rope is freaking out.

Try parenting the rope after setting the position, I had this same exact issue a month ago

Still gets flung… :confused: I’m thinking this might be a physics bug or something.

have you tried setting the Worldposition of the attachment? Position and worldposition are different

Also change the worldposition after parenting the attachments

1 Like

That fixed it! Thanks so much!
30 characters

1 Like