Change Quickbox2D parameters at runtime(friction, density..)

Hi there Box2D-community,

sadly I got another problem I can't solve by myself 🙁

This time I need to change the friction and density (and maybe some other parameters) of a QuickObject at runtime when certain events occur.
I tried to call the SetFriction() function in the b2FixtureDef class but I couldn't figure out a way to access it with my QuickObject. Is there an easier way to get it done or could you please explain me how to access that function? I'm pretty sure it would work...

Thanks in advance
Since this thread is one of the first Google results for "change friction quickbox2d", I figured I'd go ahead and share what I found. This technique is a handy way of making a player character not slide when standing still on the ground, too. Really comes in handy.

Changing the properties of an object dynamically is actually pretty easy:

Code:
player.shape.m_friction = 0;


However, you'll notice that if the object (in this case, our player character) was already touching something, that newly updated friction value won't start working until the objects disconnect and reconnect. That's because Box2D uses a cache to store the friction values of contact points, instead of doing the calculations every frame. In order to clear the cache, you just need to call:

Code:
sim.w.Refilter(player.shape);


(Where "sim" is your main QuickBox instance.)

Obviously, though, you don't want to be clearing the cache every single frame. After all, it's there for a reason. Instead, update the cache only when something needs to be changed. For instance:

Code:
// Adjust friction
if(pGrounded==false||(leftHeld||rightHeld)) {
   if(player.shape.m_friction != 0) {
      player.shape.m_friction = 0;
      qb.w.Refilter(player.shape);
   }
} else {
   if(player.shape.m_friction != 5) {
      player.shape.m_friction = 5;
      qb.w.Refilter(player.shape);
   }
}


Cheers, hope this helps! I've also emailed Zevan about this, hopefully he'll toss it on the blog so it's easier for new people to find out about.

Original thread: https://box2d.org/forum/viewtopic.php?t=7218