Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated updateConfig causes "velocity" change #101

Closed
SmitdCatchy opened this issue Jun 6, 2024 · 8 comments
Closed

Repeated updateConfig causes "velocity" change #101

SmitdCatchy opened this issue Jun 6, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@SmitdCatchy
Copy link

@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
Copy link
Contributor

frankieali commented Jun 14, 2024

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.

@frankieali frankieali added the bug Something isn't working label Jun 14, 2024
@SmitdCatchy
Copy link
Author

SmitdCatchy commented Jun 18, 2024 via email

@frankieali
Copy link
Contributor

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 frankieali self-assigned this Jun 18, 2024
@frankieali
Copy link
Contributor

frankieali commented Jun 19, 2024

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
Copy link
Contributor

Fixed with release of 1.0.13

@SmitdCatchy
Copy link
Author

SmitdCatchy commented Jun 19, 2024 via email

@frankieali
Copy link
Contributor

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
Copy link
Author

SmitdCatchy commented Jun 28, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants