PinJoint2D why do the joints stretch - bug or am I doing it wrong?

Godot Version

4.2.1

Question

I’m attempting to make a simple rope/chain for my player character that will be fired at objects so they can be carried away.

To prototype this I setup a single chain link which is pretty small 6x8 pixels (as it’s supposed to look pretty thin and the main sprite it’s going to dangle from isn’t large)

I make a rigidbody2d scene to add the rope sprite and collider and then put 10 of these end to end and use pinjoint2d’s to join them together (adding a staticbody2d at the top so the rest will hang off of it)

While this has the desired effect in terms of the bodies reacting rather like a rope, I notice that the joints separate when they are moved quickly. I’ve got simple code that just moves the origin of the staticbody2d to the mouse pointer and the rope can literally double in size when this moves over a large distance fast.

I thought the point of the softness property was to define how stretchy you want the joints - where 0 is “not stretchy at all”. It does feel like a bug to me, unless Ive either misunderstood of mis-implemented the ides?

I’m kinda a Godot rookie, so you may have already tried this, but I noticed there’s also a bias setting that sounds similar to what you’re describing?

Maybe increasing that could help?

1 Like

Cheers - I did try the high bias. I do find that setting to the max of 0.9 can make the whole rope goa bit crazy for a while, but the joints still separate out a lot

1 Like

Few more bits of info to demonstrate things. Here’s a pic of how my bodies are pinjoined together

…and here’s a quick video showing the rope in action. I set it up to be pretty thin as mentioned, so it can be a little difficult to see. So in the 2nd part of the video I use line2d to draw between each of the bodies which are supposed to be joined - so it’s clear to see how much they are stretching

Currently having the same problem but in 3D joints, after switching to the Jolt physics engine (which I understand could become default in the future), there’s a setting that seems to reduce that elasticity effect:

In Project Settings > Physics > Jolt 3D there’s a “Position correction” setting that seems to, not cancel, but at least reduce its effect if put to the max, at 100% (key: physics/jolt_3d/solver/position_correction).

Note: So far I haven’t seen a setting on the joint node or node tree configuration that seems to correct that elasticity other than in the settings

Cheers - I saw jolt earlier and thought it would help, but it’s 3D only, so no help on my 2D issue. I was able to minimise the stretch by reducing the weight at each stage - it’s a bit of a faff to do, but I have a ridigbody object that weights 50kg, so I attach the first link of the rope to it and that rope weighs 20kg, then the next link is 10, 5, 2.5… and I keep halving it as I go. This way, the sum of everything below the link always weights slightly less that the thing it’s all attached to.

While this did a better job at minimising the stretch, it’s not good enough for me, I can still catch part of my rope on scenery and then it goes crazy.

My current task is to use CharacterBody2D links and do the physics myself - which sounds awful, since I’m a bit clueless in terms of physics, but I can learn

1 Like

I’ll just leave this here, there two addons that help a lot:

  • Rope2D (not tested)
  • Rope3D - It needs some tweaking and follow the github instructions but it works.

The source code for Rope3D actually helps understanding how to fix the problem but not why the problem is there in the first place, let’s hope joints get a fix in the future !

Thanks for these - I had already come across them. Rope2D was essentially doing the same as I was - it’s just code to dynamically create a rope from rigidbody components.

I didn’t see anything that enlightening in the Rope3D stuff - certainly as much as the fixing was concerned. So my solution - after checking out some details of how physics actually worked… which in the main part blew my tiny mind was to use the much simpler idea of verlet integration. Not something I’d heard of before, but it’s a very interesting approach to modelling physics where all you are looking at is a points position and previous position to infer velocity (and then you can add forces onto that like gravity, friction etc)

There’s really useful tutorials I found here

which is a 4 part on Verlet, but is very simple to follow and understand.

Following this, the reason for the stretch is a bit more understandable. Using Verlet Intergration which add a constraint to each link of the rope - basically saying that each link is 50 pixels long for example. During the calculations on the individual points, the length could easily vary, and so you need to adjust things during the calculations. By adding more links, your error rate will increase.

You can combat this by running through the point correction part of you code more than once. This will effectively change your rope from a very stretchy one, to a much tighter one.

However, there’s a trade off here. If you make the rope to tight, then the corrections will spring your rope back far too powerfully.

I’ve messed around and am pretty happy with this 40 link idea. There’s a little stretch there but it’s within the acceptable limits for me.

The main thing is hainvg more control over the movement whereas a righidbody would always do it’s own thing. I’m generating this with line2D right now. I think the better idea is to texture the lines and let them stretch slightly. I still have to add colliders to this and need to work on letting the rope dynamically grow/retract, but I’m at a place where I can move forwards.

I would like to see the pinjoint have an option to actual pin the joint… y’know, its in the name isn’t it?