[2D] Any advice on how to deal with rope / chain tension? (+1 other question)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Plug N’ Play

I’m trying to implement a grapple gun with a physical rope and a weighted grappler. The idea is that the grappler hook will get stuck on the edge of a rigid cliff and allow you to winch the rope up to the top of it. Seems doable, right? Just create a bunch of small RigidBody2D objects, link them together with a PinJoint2D, link the gun to the beginning and the hook to the end and you’re done!

In practice, though, Godot REALLY doesn’t like tension in any direction on PinJoints. So if the grapple hook gets stuck on something and I put even a little tension on it, the rope gets sent to the shadow realm. This is especially frustrating if your player character is a KinematicBody2D.

MY QUESTIONS: If I were to make a grapple hook with a physical rope, How do I…

  1. properly make the rope appear to shoot out of the grapple gun?
  2. Keep tension on the PinJoint2Ds to a minimum so that the rope doesn’t yeet itself out of existence? (ie progressively impede the Player from moving away from the rope if it’s too tight.)

Thanks in advance for the help!

:bust_in_silhouette: Reply From: quewon

This might not work, but since this question doesn’t have any answers, here’s my best shot:

  1. Get the distance from the player to the end of the grappling hook.
  2. If distance > length of rope, get the direction vector D from the player to the hook. Multiply D by (rope length - distance). Then subtract that from the player’s velocity.

Alternatively you could try getting the direction vector from the player to the first segment in the rope. If so, then you would have to check if distance > [maximum allowed distance between player and first segment].