Rope (implemented like Bridge) quirks.

Discuss issues specific to the Flash/AS3 port of Box2D
Erin Catto
Site Admin
Posts: 2948
Joined: Thu Sep 06, 2007 12:34 am

Re: Rope (implemented like Bridge) quirks.

Postby Erin Catto » Thu Nov 20, 2008 5:23 pm

One thing to keep in mind is the hierarchy. The iterative solver has trouble with light objects supporting heavy objects. So stacking a heavy box on a light box will lead to instability (the lower box will pop out like a watermelon seed). The opposite scenario is perfectly stable, a light box on top of a heavy box is more stable than two boxes of equal mass.

So having a heavy helicopter supporting a light chain is no problem. The problem is using the light chain to lift a heavy object.

Certain trade-offs were made in the design of Box2D, and the solver design is at the core of this.

I haven't tried this, but if you know the configuration of the chain and the cargo, you might be able to deduce the weight felt by each linkage. You can use this to initialize the joint impulses. (this might require modifying Box2D a bit) This would get a bit tricky if there are contacts.

Another thing you can to to improve stability is to increase the rotational inertia of the links (without increasing the mass).

makc
Posts: 65
Joined: Tue Oct 14, 2008 1:30 pm
Contact:

Re: Rope (implemented like Bridge) quirks.

Postby makc » Mon Nov 24, 2008 5:05 pm

I have somewhat similar problem with ragdoll revolute joints. When something happens to be inbetween the body and the arm, it gets ripped out of sockets. how come all the ragdoll parts penetrate each other with no problems, but this little circle has so much power? And how do I enforce joints "priority" over collisions?
Attachments
doll.JPG
doll.JPG (8.79 KiB) Viewed 8561 times

makc
Posts: 65
Joined: Tue Oct 14, 2008 1:30 pm
Contact:

Re: Rope (implemented like Bridge) quirks.

Postby makc » Mon Nov 24, 2008 5:24 pm

a ha, I knew this was something about green color, getting that little thing some mass and holding it in place with SetLinearVelocity + SetXForm every frame did the trick, no sockets been hurt while simulating this :)

micapolos
Posts: 4
Joined: Wed Nov 19, 2008 2:04 pm

Re: Rope (implemented like Bridge) quirks.

Postby micapolos » Wed Dec 03, 2008 1:03 pm

Hi,

I'd like to share with you the results of my experiments with implementing a "STRONG" rope.
Below you'll find a code snippet in Java.
You can see the results here: http://www.dustedpixels.com/download/webstart/RopeDemo.jnlp
The rope on the left is the "strong" one, the rope on the right is the "ordinary" one.
As a point of reference, the box connected to the rope is 500x heavier than every of the links.

Code: Select all

    private static final int COUNT = 16;
    private static final boolean STRONG = false;

    // Create links. Last link will be a very heavy box.
    List<Body> links = new ArrayList<Body>();
    for (int i = 1; i <= COUNT; i++) {
      BodyDef bodyDef = new BodyDef();
      bodyDef.position = anchor.add(new Vec2(0, i * 0.25f));
      Body link = world.createBody(bodyDef);
     
      if (i != COUNT) {
        // A link
        CircleDef circleDef = new CircleDef();
        circleDef.radius = 0.025f;
        circleDef.density = 1f;
        link.createShape(circleDef);
      } else {
        // A box attached at the end of the rope
        PolygonDef polygonDef = new PolygonDef();
        polygonDef.setAsBox(0.5f, 0.3f, new Vec2(0, 0.3f), 0);
        polygonDef.density = 1f;
        link.createShape(polygonDef);
      }

      link.setMassFromShapes();
      links.add(link);
    }
   
    // Connects links together. First link is connected directly to the "ceiling".
    Body lastLink = null;
    for (Body link : links) {
      DistanceJointDef distanceJointDef = new DistanceJointDef();
      if (lastLink == null) {
        distanceJointDef.initialize(link, world.getGroundBody(), link.getPosition(), anchor);
      } else {
        distanceJointDef.initialize(link, lastLink, link.getPosition(), lastLink.getPosition());
      }
      world.createJoint(distanceJointDef);     
      lastLink = link;
    }

    if (STRONG) {
      // To make rope stronger, connect each link directly to the ceiling.
      for (Body link : links) {
        BodyDef bodyDef = new BodyDef();
        bodyDef.position = anchor;
        Body attachement = world.createBody(bodyDef);
         
        MassData massData = new MassData();
        massData.mass = link.getMass();
        massData.I = link.getInertia();
        attachement.setMass(massData);
               
        RevoluteJointDef revoluteJointDef = new RevoluteJointDef();
        revoluteJointDef.initialize(attachement, world.getGroundBody(), attachement.getPosition());
        world.createJoint(revoluteJointDef);
         
        PrismaticJointDef prismaticJointDef = new PrismaticJointDef();
        prismaticJointDef.initialize(attachement, link, link.getPosition(), new Vec2(0, -1));
        prismaticJointDef.enableLimit = true;
        prismaticJointDef.lowerTranslation = 0;
        prismaticJointDef.upperTranslation = (link.getPosition().y - anchor.y);
        world.createJoint(prismaticJointDef);
      }
    }


Regards,
Michal.

makc
Posts: 65
Joined: Tue Oct 14, 2008 1:30 pm
Contact:

Re: Rope (implemented like Bridge) quirks.

Postby makc » Wed Dec 03, 2008 2:27 pm

Michal, this code ROCKS! As a free service for everyone, here's HelloWorld.as -compatible translation:

Code: Select all

    var COUNT:int = 16;
    var STRONG:Boolean = !false;

   var anchor:b2Vec2 = new b2Vec2 (5, 0);

    // Create links. Last link will be a very heavy box.
    var links:Array = [];
    for (var i:int = 1; i <= COUNT; i++) {
      var bodyDef:b2BodyDef = new b2BodyDef();
      bodyDef.position = anchor.Copy(); bodyDef.position.Add(new b2Vec2(0, i * 0.5));
      var link:b2Body = m_world.CreateBody(bodyDef);
     
      if (i != COUNT) {
        // A link
        var circleDef:b2CircleDef = new b2CircleDef();
        circleDef.radius = 0.025;
        circleDef.density = 1.0;
        link.CreateShape(circleDef);
      } else {
        // A box attached at the end of the rope
        var polygonDef:b2PolygonDef = new b2PolygonDef();
        polygonDef.SetAsBox(0.5, 0.3)//, new b2Vec2(0, 0.3), 0);
        polygonDef.density = 1.0;
        link.CreateShape(polygonDef);
      }

      link.SetMassFromShapes();
      links.push (link);
    }
   
    // Connects links together. First link is connected directly to the "ceiling".
    var lastLink:b2Body = null;
    for each (link in links) {
      var distanceJointDef:b2DistanceJointDef = new b2DistanceJointDef();
      if (lastLink == null) {
        distanceJointDef.Initialize(link, m_world.GetGroundBody(), link.GetPosition(), anchor);
      } else {
        distanceJointDef.Initialize(link, lastLink, link.GetPosition(), lastLink.GetPosition());
      }
      m_world.CreateJoint(distanceJointDef);     
      lastLink = link;
    }

    if (STRONG) {
      // To make rope stronger, connect each link directly to the ceiling.
      for each (link in links) {
        bodyDef = new b2BodyDef();
        bodyDef.position = anchor;
        var attachement:b2Body = m_world.CreateBody(bodyDef);
         
        var massData:b2MassData = new b2MassData();
        massData.mass = link.GetMass();
        massData.I = link.GetInertia();
        attachement.SetMass(massData);
               
        var revoluteJointDef:b2RevoluteJointDef = new b2RevoluteJointDef();
        revoluteJointDef.Initialize(attachement, m_world.GetGroundBody(), attachement.GetPosition());
        m_world.CreateJoint(revoluteJointDef);
         
        var prismaticJointDef:b2PrismaticJointDef = new b2PrismaticJointDef();
        prismaticJointDef.Initialize(attachement, link, link.GetPosition(), new b2Vec2(0, -1));
        prismaticJointDef.enableLimit = true;
        prismaticJointDef.lowerTranslation = 0;
        prismaticJointDef.upperTranslation = (link.GetPosition().y - anchor.y);
        m_world.CreateJoint(prismaticJointDef);
      }
    }   
Attachments
HelloWorld.zip
(51.42 KiB) Downloaded 817 times

szataniol
Posts: 4
Joined: Wed Jun 25, 2008 3:08 am

Re: Rope (implemented like Bridge) quirks.

Postby szataniol » Fri Dec 12, 2008 6:03 am

The problem is when you remove joints drawings and actually try to make it look like a real rope. If you move it it would never stop and move slightly all the time. :(

makc
Posts: 65
Joined: Tue Oct 14, 2008 1:30 pm
Contact:

Re: Rope (implemented like Bridge) quirks.

Postby makc » Fri Dec 12, 2008 11:58 am

szataniol wrote:If you move it it would never stop and move slightly all the time. :(

Manual wrote:You can use a joint motor to simulate joint friction. Just set the joint speed to zero, and set the maximum torque to some small, but significant value. The motor will try to prevent the joint from rotating, but will yield to a significant load.

darkzerox
Posts: 241
Joined: Fri Dec 07, 2007 3:09 pm

Re: Rope (implemented like Bridge) quirks.

Postby darkzerox » Fri Dec 12, 2008 11:17 pm

That looks awesome guys! Thanks for sharing.

micapolos
Posts: 4
Joined: Wed Nov 19, 2008 2:04 pm

Re: Rope (implemented like Bridge) quirks.

Postby micapolos » Tue Dec 16, 2008 7:14 pm

szataniol wrote:The problem is when you remove joints drawings and actually try to make it look like a real rope. If you move it it would never stop and move slightly all the time. :(


I'm not sure if I'm thinking about the same "slights movements" as you.
If yes, then the solution to that problem is simple.
You need to slightly "loose" the prismatic joint which attaches link to the ceiling,
by modifying 3-rd but last line in the Java code snippet like that:

Code: Select all

prismaticJointDef.lowerTranslation = -0.01f * (link.getPosition().y - anchor.y);


Did it help?

Regards,
Michal.

clipdepelicula
Posts: 3
Joined: Tue Feb 24, 2009 3:06 am

Re: Rope (implemented like Bridge) quirks.

Postby clipdepelicula » Thu Jun 11, 2009 10:01 am

Please can you send me the class?? Im beginer and I dont know how to initialize it. Sorry for my english. :roll:

Thanks

administraor@gmail.com


Return to “Flash”



Who is online

Users browsing this forum: Bing [Bot] and 0 guests