Open jakehockey10 opened 6 years ago
Silly mistake. Added my check to animate...
@byWulf Does this example as I have it always return 1, 2, 3, 4, 5 results? I was assuming that the dice would have random results for each through, but I keep getting the results 1, 2, 3, 4, 5 every single throw. Can you explain what's going on? Thanks!
@byWulf I've identified when the physics of the dice throw is finished. But is there a way to identify when the animation is done? I seem to know what the results of the dice throw is going to be well before the animation is over and I'm not sure how the animation side of things works. Thanks!
Hey :) Sorry for the late response. I'm currently moving to a new city so time is short.
The purpose of this lib is to have random throws but with fixed upper sides. You define the side, which should be up after the throw, before the throw in the DiceManager.prepareValues() method.
DiceManager.prepareValues({dice: 0, value: 1});
Will throw dice 0 so it lands on side 1.
let randomValue = Math.floor(Math.random * 6) + 1;
DiceManager.prepareValues({dice: 0, value: randomValue});
Will throw dice 0 so it lands on the random generated side. You will have the upside value before the throw in randomValue
.
Internally the system first "simulates" the throw and looks, what side is up. And then for the real throw it replaces all sides (and the simulated upper side with the wished value) and then executes the real throw. As the physics don't change, the switched upper side after the throw will be your defined side.
Hope I could help you!
@byWulf The check
in prepareValues
seems return allStable
as true
right at the start, compared to Teal's version, where he displays the results label at the end when the visuals have played out.
Hello,
I've gotten your library to work in an Angular 5 application while following this example: https://github.com/byWulf/threejs-dice/blob/master/examples/rolling.html.
How would I go about identifying when the dice have all settled and then get the number that is on the upper face?
This is my code:
If I add an event listener to the world's postStep method and do my checks there, like in the commented out section of the
randomDiceThrow
method, then my whole scene goes black and nothing is happening. I'd like to know when they are all stable by usingisFinished()
on all of them and then get their upside value (usinggetUpsideValue
). I tried usingemulateThrow
that has the callback, but then there is no animation.I'm sorry if these are noob questions. Thanks!