If I were to set both the dynamic and static friction coefficients for a contact pair based on their materials on collision, will the collision response factor in the new coefficients?
In other words is the collision response, based on friction coefficients, worked out before the collision delegates are called?
Setting dynamic & static friction coefficients on collision?
-
- Posts: 249
- Joined: Wed Nov 17, 2010 1:49 pm
Re: Setting dynamic & static friction coefficients on collis
Material properties for a collision pair are computed at pair initialization, when a pair of objects' AABBs first overlap.
The immediate version of the collision pair created event is called after the collision pair has been initialized, but before any collision detection/response occurs. If the material properties are changed within an CreatingCollisionPair event, the new data will be used instead of the initialized values.
The immediate version of the collision pair created event is called after the collision pair has been initialized, but before any collision detection/response occurs. If the material properties are changed within an CreatingCollisionPair event, the new data will be used instead of the initialized values.
-
- Posts: 249
- Joined: Wed Nov 17, 2010 1:49 pm
Re: Setting dynamic & static friction coefficients on collis
Excellent, thank you.
What if multiple AABBs are overlapping? How will the correct material be set if potentially 3 or more objects are going to collide?
Code: Select all
entity.EventManager.CollisionPairCreated += new CollisionPairCreatedEventHandler(CollisionPairCreated);
Re: Setting dynamic & static friction coefficients on collis
Careful, there are immediate and deferred versions of each event. The CollisionPairCreated event is deferred, which means it runs sequentially at the very end of the update. It won't change the material in time for the first collision detection/response update. The present tense "CreatingCollisionPair" is the one to use to modify collision pair properties in the line of execution.
The material properties stored in a collision pair are the blended material properties of only its two managed entities. If you have multiple objects overlapping, there will be multiple pairs which each manage only two entities at a time with pair-specific material properties. Note that the entity's own material properties would not change from this event (it is unnecessary and unsafe to do so), only the blended interpretation of the pair.What if multiple AABBs are overlapping? How will the correct material be set if potentially 3 or more objects are going to collide?
-
- Posts: 249
- Joined: Wed Nov 17, 2010 1:49 pm
Re: Setting dynamic & static friction coefficients on collis
Ah gotcha now. Thanks for explaining that, it makes more sense. 

Code: Select all
private void CreatingCollisionPair(Entity sender, Entity other, CollisionPair pair)
{
// Set friction coefficients for each collider in the pair (not the entity itself)
// - Note that the entity's own material properties would not change from this event (it is unnecessary and unsafe to do so)
// - Only the blended interpretation of the pair is changed
pair.ColliderA.StaticFriction = Constants.STATIC_FRICTION_COEFFICIENTS[index];
pair.ColliderA.DynamicFriction = Constants.DYNAMIC_FRICTION_COEFFICIENTS[index];
pair.ColliderB.StaticFriction = Constants.STATIC_FRICTION_COEFFICIENTS[index];
pair.ColliderB.DynamicFriction = Constants.DYNAMIC_FRICTION_COEFFICIENTS[index];
}