3d-dice / dice-box

3D Game Dice for any JavaScript App
https://fantasticdice.games/
MIT License
108 stars 26 forks source link

Repeated updateConfig causes "velocity" change #101

Open SmitdCatchy opened 1 month ago

SmitdCatchy commented 1 month ago

@frankieali If I want to roll different amount of dice each time and rescale them to fit the canvas area and I call updateConfig() the dice seem to be getting "quicker" to the point when they are starting to "twitch" on landing. This behavior appears after a fe hundred dice being rolled consistently for me.

frankieali commented 3 weeks ago

I'll look into it. Can you give me a few more details on how to recreate this issue? The throwForce and mass of the physics colliders are tied to the scale setting so there might be a math issue that's adding up over time. Dice twitching might be associated with mass eventually dropping to zero.

SmitdCatchy commented 2 weeks ago

Many thanks! Sure I can.

So basically in the application there are different characters which roll different type and number of dice that is why I have to change the number and scale of the dice.

I created a service which initializes the dicebox and before each call check the dice type and number and calls the updateConfig with the new scale value, the mass and other attributes are untouched on my part.

But after nearly 10 rolls of many dice this velocity issue occures.

Sadly, I cannot share the codebase with you, but will ask about a code snippet from the service if it is any help.

On Fri, 14 Jun 2024, 17:01 Frank, @.***> wrote:

I'll look into it. Can you give me a few more details on how to recreate this issue? The throwForce and mass of the physics colliders are tied to scale setting so there might be a math issue that's adding up over time. Dice twitching might be associated with mass eventually dropping to zero.

— Reply to this email directly, view it on GitHub https://github.com/3d-dice/dice-box/issues/101#issuecomment-2168226079, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEOG2U5MGCZOYVPRIY4HKCTZHMATFAVCNFSM6AAAAABI5NGWFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRYGIZDMMBXHE . You are receiving this because you authored the thread.Message ID: @.***>

frankieali commented 2 weeks ago

Yup, I can tell from this demo, where I randomly change the scale, that the throwForce drops to zero. I'll see if I can get it fixed. https://codesandbox.io/p/sandbox/dice-es6-module-cdn-forked-kjjhrl

frankieali commented 2 weeks ago

Looks like you can get around this defect by setting the throwForce config option when you first initialize the DiceBox

let Box = new DiceBox("#dice-box", {
  assetPath: "assets/",
  origin: "https://unpkg.com/@3d-dice/dice-box@1.0.12/dist/",
  scale: 6,
  throwForce: 5,
  spinForce: 6,
  gravity: 1,
  mass: 1,
});

There seems to be a mixup as to what value should be used as the base value when calculating throwForce. Setting it on initialization keeps the base value stable. Not setting the throwForce value means the previous computed value gets recomputed, slowly making the value smaller.

This seems to also be true for gravity, spinForce and to a lesser extent mass.

frankieali commented 2 weeks ago

Fixed with release of 1.0.13

SmitdCatchy commented 2 weeks ago

Awesome, thank you so much!

On Wed, Jun 19, 2024 at 3:12 PM Frank @.***> wrote:

Fixed with release of 1.0.13

— Reply to this email directly, view it on GitHub https://github.com/3d-dice/dice-box/issues/101#issuecomment-2178690191, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEOG2U3X4IUP2O4BM5TOL6TZIF7T7AVCNFSM6AAAAABI5NGWFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZYGY4TAMJZGE . You are receiving this because you authored the thread.Message ID: @.***>

frankieali commented 1 week ago

I just noticed that I accidentally introduced a bug with the fix in 1.0.13. It was related to scale and how the config options might have been updated with undefined values. I just posted version 1.0.14 to fix this.

SmitdCatchy commented 1 week ago

Thank you for the heads up!

On Thu, 27 Jun 2024, 21:10 Frank, @.***> wrote:

I just noticed that I accidentally introduced a bug with the fix in 1.0.13. It was related to scale and how the config options might have been updated with undefined values. I just posted version 1.0.14 to fix this.

— Reply to this email directly, view it on GitHub https://github.com/3d-dice/dice-box/issues/101#issuecomment-2195488885, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEOG2UYHMU23GZPV3QGQ5G3ZJRPQVAVCNFSM6AAAAABI5NGWFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJVGQ4DQOBYGU . You are receiving this because you authored the thread.Message ID: @.***>