Only 1 contact updated on setFriction: plus Solution

0 favourites
  • 4 posts
From the Asset Store
About 900+ game portals: 400 e-mails, 514 contact/submit forms (last update: 2022, October, +275 contacts)
  • I posted this in the closed bug forum : https://www.scirra.com/forum/friction-bug-contacts-can-be-updated_t124639 , but I remembered that you don't necessarily check there. So I am putting this here.

    b2body.GetContactList(); isn't meant to return a list but rather a single b2ContactEdge object. you can get the next object in the list (managed by the body) by using .get_next(); However, there is a bug in ams.js that causes .get_next() to always return an object, even at the end of the list. So, you have to use a workaround; Box2d.getPointer( B2ContactEdge ) !==0;

    The following code resets friction across all contacts, and worked fine with the tests I ran.

    In SetFriction:

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

    Box2D.getPointer(contactEdge) !==0;

    contactEdge = contactEdge.get_next())

    {

    var contact = contactEdge.get_contact();

    if (contact)

    contact.ResetFriction();

    }

    Sorry for the double post if you read the other. I just wanted to make sure you got this! It took way to long to figure out and I didn't want anyone repeating the work if they didn't have to. ... and sorry for not following proper bug posting. I didn't think it was needed here, as it is a known bug.

    relevant post: https://github.com/kripken/box2d.js/issues/17

  • OK, updated for the next build. I'm not clear on how far get_next() will go though - will it continue to iterate through all contacts in the world? That would impact performance. But added it anyway so it works correctly.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ashley - As far as I can tell, contactedge.get_next() is only supposed to go through the contacts connected to the body in question. if you use contact.next(), that will go through all contacts in the world. But without using box2d.getpointer() the loop will run forever and contactEdge.get_next() keeps returning empty b2 contact edges.

    I edited the code to count how many times the loop is running... It runs only as many times as there are physics contacts affected the body. So it looks like it is running as it should.

  • OK, good to know - thanks.

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