Box2d RopeJoint bug - fix or alternative solution?

Viewed 57

What I am trying to do is to create rope game. Below you can find a movie how it looks like now.

https://youtu.be/QTULCGNF70I

I am using RopeJoint and I am reducing maxLength each frame to be able to accelerate. Everything seems fine, but the problem appears for bubble kind of ball. I realized that shortening rope does not increase balls velocity. For example if I throw the rope fully vertical and the only "force" is from shortening the rope, the velocity is 0,0. Seems like, body movement is not simulated?

After I let the rope go the momentum is lost. The bubble can fly, but the factor from rope shortening is ignored.

I don't know if you understand what I mean. The movie should clarify it better.

Workarounds I tried:

  • Good idea was to use prismaticJoint, but the rotation is fixed, so it doesn't work. I couldn't swing
  • Another idea was to use wheelJoint and make use of it's frequency parameter. However here there's a problem that rope becomes rubber. Swing feeling is bad, when it can extend more than initial length, it should always only shorten.

Solutions I see, but they are not available

  • RopeJoint which keeps body momentum from rope shortening
  • PrismaticJoint without fixed rotation
  • WheelJoint with possibility to set max length or create the rope with it's max length, not the rest position.
1 Answers

I want to share with you how I handled it finally.

  1. I shoot a "ropeBullet" which is small circular box2d body, by setting it's velocity and angle. I render a rope graphic between bullet and ball.
  2. When bullet reaches wall, I get from contactListener the point of contact
  3. I connect the bullet and the wall with revoluteJoint, based on bullet center and contact point. Thanks to such solution, the bullet may rotate and swinging on the rope is possible.
  4. On the other end of the rope I created "rotor" which is similar circular body. It is connected to the ball body all the time with another revoluteJoint to two centers. It allows the ball to rotate freely.
  5. Now I connect ropeBullet and the rotor with prismaticJoint. Axis i set by calculating the vector between them and normalizing it.
  6. I set up a prismatic joint limits, motor speed and max force according to my needs.
  7. The ball is touched by the gravitation force of the world, so I had to made one more trick to make it satisfying. I described the problem and the trick on box2d reddit so I refer to it: https://www.reddit.com/r/box2d/comments/gpdmoc/prismatic_joint_behaves_like_rubber/
Related