# Contact friction for overlapping rectangles

I am currently developing a top-down "tabletop simulator" where you are able to drag, drop and rotate playing cards on a table. The cards are able to overlap but do not interact as of yet. What I now want to implement is that whenever a card is being dragged over another card, that the bottom starts moving as a result of the dynamic friction between the overlapping cards. Right now I am thinking of two ways to approach this:

• Determine the area of overlap and use the center of mass of this area as the point where the friction force is acting on
• Rasterize the cards and determine the overlapping raster and let the friction force act on these points.

Unfortunately I expect these methods to be computationally demanding and was wondering if there are more efficient methods out there. So far I have not found any material referencing this type of problem. I assume it relates to determining the area of contact for 3D objects and applying a friction force.

• You’re really better off cheesing it than actually trying to calculate friction in this way, especially for overlapping 2D boxes. Attempting to physically simulate this behavior will result in countless hours of frustration, especially because you are implementing essentially 3D physics with 2D objects, and friction in essentially all realtime physics engines is handled in a way that conforms to the type of solver used. Source: AAA physics programmer
– Jon
Jan 12, 2021 at 20:35
• I totally agree, probably the biggest lesson I've learned is that I am developing a game, not a physics simulator. So I've come to terms that my physics are a somewhat rough emulation of the real world. That being said, do you have any suggestions on cheesing this behaviour? Jan 12, 2021 at 21:13
• Yeah, one of the simplest solutions in my opinion would be to simply calculate the overlap of the shapes as seen here gamedev.stackexchange.com/questions/586/… and instead of discarding the values they calculated in that function, use a threshold that feels right to you. Say, for example, if 70% of the card is overlapped, you could simply “parent” the transform matrix of the lower card to the transform of the card on top. youtu.be/SZChVvy4enQ . Add in some linear interpolation to maybe slide the card in to place.
– Jon
Jan 12, 2021 at 23:14