drwhut / tabletop-club

An open-source platform for playing tabletop games in a physics-based 3D environment for Windows, macOS, and Linux! Made with the Godot Engine.
https://tabletopclub.net
MIT License
1.27k stars 55 forks source link

Bug: Larger cards are shuffled when dropping them #116

Closed elmodor closed 1 year ago

elmodor commented 1 year ago

Describe the bug When dropping a card stack which consists of larger cards, the cards are shuffled. This might be related to an issue that these cards are clipping through the table.

To Reproduce Steps to reproduce the behavior:

  1. Edit assets/TabletopClub/cards/config.cfg
  2. Change scale to: "scale = Vector3(13.23, 1.0, 22.62)"
  3. Start TabletopClub, Singleplayer
  4. Objects -> Add some different cards (3 to 6)
  5. Pick up stack and let go
  6. Cards are shuffled (most of the time - if not, go back to step 5)

Expected behavior Cards are not shuffled

Screenshots shuffle.webm

Environment Arch Linux

Version v0.1.0 Beta 1

elmodor commented 1 year ago

This does also happen on normal cards when they hit the tables edge or are thrown around.

I guess the problem is that Stack.gd _physics_process calls request_shuffle() - so basically whenever there's a physics process the cards are shuffled. is_being_shaked checks the velocity if it is "shaken". So maybe this velocity threshold is wrong?

This is the velocity when the card stack hits the edge and bounces back: 48369.363281

Force when a stack is clipping through the table and bumped up: 3599.904541

I think the velocity can't be used to indicate if it is being shaken. At least not the current and last velocity.

drwhut commented 1 year ago

It basically checks to see if the acceleration switches direction by a given amount - having said that, wouldn't this be solved by having it also check to see if the stack is hovering? Since we only want this to happen if the stack is hovering anyway.

elmodor commented 1 year ago

I tested it, and yes it fixes this issue. But it still gets shuffled on other occasions where it shouldn't. With the hovering fix the stack does not get shuffled when clipping/on table edge. But it still gets shuffled:

The first one I can see to be happening a lot more unintentionally - you drop a card stack but decide to pick it up again.

Having another condition checking if the piece changed orientation quickly in the last x seconds while being hovered and having the acceleration change?

drwhut commented 1 year ago

Hmm... maybe it might be simpler to just disable shuffling for the first 0.5-1 seconds that a stack is hovered? I think that would cover both cases you mentioned.