0
\$\begingroup\$

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.
\$\endgroup\$
7
  • \$\begingroup\$ How is the "bubble" ball configured differently from the other ball that's working as desired? \$\endgroup\$ – DMGregory Apr 18 '20 at 17:43
  • \$\begingroup\$ It's "heavier" so the fake gravity force which I appliied is moving it slower. I don't use world gravity vector. All balls behave in the same way. They thing is that it's the most noticable in bubble \$\endgroup\$ – Mateusz Gaweł Apr 19 '20 at 18:57
  • \$\begingroup\$ Can you show us the code for how you apply your forces to the balls? \$\endgroup\$ – DMGregory Apr 19 '20 at 18:58
  • \$\begingroup\$ each frame I do: actor.getBody().applyForceToCenter(gravity, true); \$\endgroup\$ – Mateusz Gaweł Apr 19 '20 at 21:24
  • \$\begingroup\$ private final Vector2 gravity = new Vector2(0, -15); \$\endgroup\$ – Mateusz Gaweł Apr 19 '20 at 21:24
1
\$\begingroup\$

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/
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.