Friction bug... contacts can be updated

Bugs will be moved here once resolved.

Post » Tue Feb 10, 2015 9:54 pm

change-friction-bug-contacts-need-to-be-updated_t124508

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.

contactClassObjectInstance.resetFriction();
Last edited by ruskul on Fri Feb 20, 2015 1:03 am, edited 1 time in total.
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Sat Feb 14, 2015 6:40 pm

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:

box2dContactEdge.contact.ResetFriction

In c++ it would look like this:

for ( Box2dContactEdge* contactEdge = body->getContactList();
contactEdge;
contactEdge = contactEdge->next();)
{
contactEdge->contact->ResetFriction();
}

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; contactEdge.next();)
{
contactEdge.contact.ResetFriction();
}

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...
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Mon Feb 16, 2015 4:45 pm

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.
Scirra Founder
B
387
S
230
G
88
Posts: 24,251
Reputation: 192,454

Post » Thu Feb 19, 2015 10:38 pm

@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.
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Fri Feb 20, 2015 12:36 am

@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)
contact.ResetFriction();
}
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 1 guest