Hi all,
I want to be able to alter friction based on the type of my bodies and am not sure how to achieve this.
I have several types of dynamic body (defined by a field in my UserData object within the box2d body). These fixtures all have a default "global" friction setting, but I want to dynamically alter the friction upon collision based on my types.
For example:
I have a concept of a "player", and in my world there are "barrels" (just circles). The barrels need friction otherwise they don't roll, but if my player collides with a barrel, I don't want any friction. I can't disable friction for the player because then he would slide about everywhere. With both bodies having friction, when the payer collides with the barrel he sort of "climbs" up on top, rather than just pushing it along which is the effect I am looking for.
Box2d is doing the correct thing, and my player (which is just a square BTW) is exhibiting expected behavior given the friction forces involved, but I need to override this behavior in this particular case.
The documentation talks about: "Tangent Impulse(s)" as:
So.. I can get access to this array from the b2ContactImpulse in the PostSolve event of my contact listener, but is it safe to tinker with these values?
Also, given the PostSolve event is triggered for a single contact, why is the tangentImpulses field an array? Obviously there is more than one value, but not sure what they correspond to.
If I detect a collision between a "player" and a "barrel" am I ok to just zero-out all values in the tangentImpulses array during the PostSolve event?
Any ideas appreciated.
Cheers,
Jason.
I want to be able to alter friction based on the type of my bodies and am not sure how to achieve this.
I have several types of dynamic body (defined by a field in my UserData object within the box2d body). These fixtures all have a default "global" friction setting, but I want to dynamically alter the friction upon collision based on my types.
For example:
I have a concept of a "player", and in my world there are "barrels" (just circles). The barrels need friction otherwise they don't roll, but if my player collides with a barrel, I don't want any friction. I can't disable friction for the player because then he would slide about everywhere. With both bodies having friction, when the payer collides with the barrel he sort of "climbs" up on top, rather than just pushing it along which is the effect I am looking for.
Box2d is doing the correct thing, and my player (which is just a square BTW) is exhibiting expected behavior given the friction forces involved, but I need to override this behavior in this particular case.
The documentation talks about: "Tangent Impulse(s)" as:
Quote:
The tangent force is generated at a contact point to simulate friction. For convenience, this is stored as an impulse.
So.. I can get access to this array from the b2ContactImpulse in the PostSolve event of my contact listener, but is it safe to tinker with these values?
Also, given the PostSolve event is triggered for a single contact, why is the tangentImpulses field an array? Obviously there is more than one value, but not sure what they correspond to.
If I detect a collision between a "player" and a "barrel" am I ok to just zero-out all values in the tangentImpulses array during the PostSolve event?
Any ideas appreciated.
Cheers,
Jason.