0
\$\begingroup\$

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.

\$\endgroup\$
3
  • 3
    \$\begingroup\$ 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 \$\endgroup\$
    – Jon
    Jan 12, 2021 at 20:35
  • \$\begingroup\$ 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? \$\endgroup\$
    – Mr Coke
    Jan 12, 2021 at 21:13
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Jon
    Jan 12, 2021 at 23:14

1 Answer 1

0
\$\begingroup\$

Assuming that you won't have thousands of cards dragging each other simultaneously, I'd go with calculating overlap area.

This seems to be good starting point: https://stackoverflow.com/questions/44797713/calculate-the-area-of-intersection-of-two-rotated-rectangles-in-python

especially this answer https://stackoverflow.com/a/45268241/14953457

\$\endgroup\$
1
  • \$\begingroup\$ Yeah I was leaning towards using that method. Instead of determining the center of the overlapping area I could instead apply forces on the vertices \$\endgroup\$
    – Mr Coke
    Jan 9, 2021 at 20:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .