Change Friction Bug... Contacts need to be updated

Bugs will be moved here once resolved.

Post » Sun Feb 08, 2015 11:07 pm

Problem Description

When friction is changed on an object at runtime, that change in friction is not reflected across current contacts. That means if you change friction of an object in contact with another physics object, that object will continue to resolve collisions with the current object using the old friction, until it leaves contact and touches again.

In this post:

viewtopic.php?t=122743

I mentioned that, "...you also have to update contacts that are already occurring between the object being changed. Box2d stores the friction in the contact and does not regenerate that information on continued contacts." This is the case. In the behavior, friction is set, but contacts are not updated. I am not certain, but I believe not updating contacts when setting density, elasticity, etc, may also have unintended results, in the same way setting friction does.

I have enclosed a CAPX file, though you probably don't need it. Use A and D to control angular velocity. The object defaults to 0 friction so it shouldn't roll any where. If you press H the objects friction is set to 1. But it still won't go anywhere...

I am using, the latest version of construct (beta). Browsers affected and windows version is not applicable.
You do not have the required permissions to view the files attached to this post.
Image
B
26
S
9
G
2
Posts: 534
Reputation: 4,678

Post » Tue Feb 10, 2015 3:41 pm

I can't find anything in the Box2D documentation about this. As far as I can tell it determines the contact friction at the beginning of the contact only, which would be why changing it during a contact has no effect. I can't find anything in the Box2D API that can update existing contacts either.

Considering physics engines are meant to be realistic, I'm not sure how they are supposed to react to an object with changing friction during a contact anyway - is that something that can happen in the real world? It seems a bit like reporting a bug when you teleport a physics object...
Scirra Founder
B
362
S
216
G
75
Posts: 23,067
Reputation: 180,321

Post » Tue Feb 10, 2015 9:51 pm

@Ashley (do I need to add @Ashley, or do you see these posts anyway?)

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();

Also, isn't whether or not something can happen in the real world is somewhat immaterial, as we are not making real world simulators? At any rate, I can think of instances where friction seems to change at run time in the real world- or at least simulating it as such is the most elegant way to program it . Friction on ice increases as the temperature drops, friction of a wheel on a road increases on a warm road compared to cold.
Image
B
26
S
9
G
2
Posts: 534
Reputation: 4,678


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 1 guest