Friction bug... contacts can be updated

0 favourites
  • 5 posts
From the Asset Store
Match same tiles with each other as fast as you can and earn more score during a limited time!
  • Here is the original bug report ^

    I am resubmitting this to add the following:

    The contact class contains a set friction and reset friction method. When you change the friction on a fixture, you then iterate through all contacts for that body and call reset Friction. You can do this at the time of friction change (best) or during presolve or really at any time. The contact class can be used to manipulate a lot of things, including overriding default mixtures for elasticity, density, friction and so on. You can even use it to ignore collisions on a frame by frame basis for oneway collisions and also use it to create tangent forces/impulses.


  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I wanted to add the following:

    The version of box2d web that comes with the behavior does not have resetfriction (which is expected, reset has to be used instead). I did a search of the ams.js file I found that it does have resetFriction burried in the garble up top. It is also supposed to be the most recent (2.2.1) version of box2d

    In 2.2.1

    Box2dBody.getContactList returns a box2dContactEdge object. Using that object you can call:

    In c++ it would look like this:

    for ( Box2dContactEdge* contactEdge = body->getContactList();


    contactEdge = contactEdge->next();)




    Now, I am rubbish at jscript as a rarely use it, but I could not manage to get this working. (in the SetFriction action underneath this.fixture.SetFriction(f); this.Friction(f);

    for (var contactEdge = this.body.GetContactList(); contactEdge;;)



    I keep getting an error about cannot call property "ResetFriction()" of undefined. Are you having anyluck with it?

    I thought maybe it has to be part of the contactListener cycle; its where people on the forums were putting it, but I read that doing it after the physics world step was fine. Well, anyway...

  • You're right, it can be updated. I've fixed this for the next build, but due to a bug in the asm.js build of Box2D, it only ever returns a single contact instead of a contact list. So it works for your example, but if it's simultaneously in contact with two objects, it will only update the friction for one of them. I'll see if we can fix the asm.js bug and update all contacts.

  • Ashley

    You might find this useful. As unintuitive as it may seem, b2body.GetContactList(); doesn't return a list of anything. It returns a single b2ContactEdge. The body maintains the list, but you can get to the next b2contactEdge by:

    contactEdge = contactEdge.get_next();

    I have it working to reset friction on more than one contact in my game now.

  • Ashley - there is a bug in .next(); it never returns null at the end of the list... as a work around box2d.getpointer(contactEdge) !== 0 serves in its place.

    The following Works in everything I did with it. It updates all contacts for the object in question! yay

    for (var contactEdge = this.body.GetContactList();

    Box2D.getPointer(contactEdge) !==0;

    contactEdge = contactEdge.get_next())


    var contact = contactEdge.get_contact();

    if (contact)



Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)