Godot Version
v4.5.1.limboai+v1.5.2.gha [f62fdbde1]
Question
The classic way of implementing a rope or other articulated segment is a sequence of RigidBody2D’s with a CollisionShape2D, often an capsule or rectangle, with a PinJoint2D at the end of the CollisionShape2D. The PinJoint2D is attached to it’s parent RigidBody2D and the RigidBody2D of the next “link” in the chain.
I have this working.
I want to gradually increase the length of the rope, however. If you imagine a rope hanging from the ceiling, subject to gravity, I would like to “unspool” the rope as if it were spooled up on a spindle at the ceiling - thus the “new rope” should come from the top, and not be added at the bottom.
Attempts Made:
A. Increase the size of the Shape2D
I’ve gradually increased the length of the Shape2D and increased the position of the PinJoint2D:
(piece.CollisionShape2D.shape as CapsuleShape2D).height = piece_length
piece.CollisionShape2D.position.y = piece_length / 2
piece.PinJoint2D.position.y = piece_length
This moves the joint and the piece, but the next rope piece remains “joint’ed” at the same place. If I double the size of the first piece, it ends up overlapping the second piece, which doesn’t move.
B. Insert another piece of the same length
var new_piece = add_piece()
var last_node_b = last_piece.PinJoint2D.node_b
last_piece.PinJoint2D.node_b = new_piece.get_path()
new_piece.PinJoint2D.node_b = last_node_b
This also adds another element, but physics then gets broken and the CollisionShape2D loses attachment on one of it’s ends.
Question
How do I increase the length of a rope, either by adding new PinJoint2D+RigidBody2Dlinks, or by changing the size of an existing link?