Change Friction Bug... Contacts need to be updated

0 favourites
  • 3 posts
From the Asset Store
About 900+ game portals: 400 e-mails, 514 contact/submit forms (last update: 2022, October, +275 contacts)
  • 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:

    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.

  • 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...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

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