Matthewek
Matthewek

Reputation: 1559

Box2d rope - NOT fixed length

I am creating game with box2d physics, I have a crane with rope attached to it, something like that (example)

enter image description here

What I am trying to achieve is to let player to fold or unfold line (to certain limits obviously) currently I am only able to create fixed length rope, which is limiting my game a little bit.

How could I achieve it? I had couple of ideas, but are rather not good ones, like recreating rope all the time, but it would just destroy my performance.

Upvotes: 0

Views: 584

Answers (1)

Eric
Eric

Reputation: 3172

First, I would check to see if that actually does ruin your performance. You might be surprised by how fast it is.

If it does, one solution is to create an array of short ropes attached to one another (say 10). This ia basically what a rope is anyway, you just need to hold on to the elements.

To make the rope be 6 units long, hide and collision disable the last 4 and attach the load to the end of the sixth rope segment.

Upvotes: 1

Related Questions