Search Unity

Dice Master - The complete solution for your rolling needs [Unity5]

Discussion in 'Assets and Asset Store' started by Catman, Oct 9, 2015.

  1. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    News
    • The asset has now been updated to version 1.1.0, with the new major feature of dynamic dice. Check the latest post!

    Asset store
    Website

    Features video
    WebGL demo
    HTML documentation


    Dice Master is the complete solution for dice creation, spawning, throwing, and runtime handling. This tool will allow you to create custom dice from scratch, no coding required. It also allows you to control the behaviour of any dice at runtime: throw and spin dice, spawn them, and check their result.

    header - Copia.png

    create.jpg spawn.jpg throwAndSpin.jpg roll.jpg

    Here is a feature list:
    • A complete editor for creating your custom dice without a single line of code
    • Numbers, pips, colors, and special sprites to create custom dice out of the box
    • Uses PBR materials to create realistic dice
    • Automatic and optimized number detection on rest, with an event-based inspector hook
    • Spawner, thrower, and spinner mechanisms included
    • Optimized textures or dynamic faces: your choice
    • Visual gizmos for dice, spawner, thrower, and spinner
    • Physics materials and masses that mimic real dice
    • 7 dice types (from D2 to D20) with default prefabs provided, plus several custom dice
    • High- and low- poly meshes for all 7 dice types
    • Test scenes for throwing, rolling, and using the runtime checking system
    • Complete HTML documentation
    • Optimized for mobile use
    • Full source code
    • Weighted dice, sound effects on hit, different gravity, and more!
    Any question, comment, suggestion, or general feedback is welcome!
     
    Last edited: Feb 25, 2016
    Gozdek likes this.
  2. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Hello! I prepared a feature demo video, take a look at it!

     
  3. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
  4. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,216
    What would be great is if there were also classes to parse dice throw strings in to integer values and then also into on the spur objects/animations. Then this asset would sit well with any inventory system
     
  5. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Hi Duffer123, thanks for the suggestion! However, I am not sure I understood what you meant by dice throw strings and parsuing them into spur objects, could you please elaborate on that?
     
  6. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,216
    So if I had a string value of "2D4 + 5" you could both either (a) provide an introduction value of the result of that throw (having accurately parsed the above string) or (b) generate the relevant models and animation etc. ?
     
  7. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    I see, I like the idea, I can create a spawner that takes as input the string and then throws the dice as needed. Models should be provided beforehand, as they do not change from one throw to the next.

    I think I will add something similar in the next update, thanks for the tip!
     
  8. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,216
    To be honest, try and do a and b separately. If you can do a really good job of a, perhaps using regular expressions, people will buy the Asset just for that...
     
  9. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Yep, that's my idea as well, the parser is a nice idea. regexps are a bit overkill for the purpose, however, as the strings are quite simple!
     
  10. Eggpunk

    Eggpunk

    Joined:
    Nov 2, 2014
    Posts:
    39
    Is it possible to get the results of dice that are spawned? I've been going over the examples (that all appear to use dice already in the scene) and following those, I can only seem to get the results of test dice in the scene.

    The Dice segment "On Show Number (Int32) only gives me the options of "no function" and monoscript if I try to use a prefab of a nice that has not yet spawned.

    I tried aiming at the clones that came up during Play but those results obviously did not stick.
     
  11. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Hi TomaTantrum. Yes, it is possible! However, it's true I did not provide an example for this in the scripts.
    I'll show you how to do that.

    You are going in the right direction, as you do need to attach to the spawned dice's onShowNumber event.

    We could do that in two ways:
    - iterate over the dice in the scene, keep a reference to them, and then react when a new dice is met.
    - wait for a dice to be spawned and then react to a spawn event.

    We will use the second approach as it is better. It requires us however to modify the Spawner class to add a new event, onSpawnDice. This is triggered whenever a new dice is spawned and it returns the dice itself.
    You will find the updated Spawner class as an attachment here. I will make sure to add this to the next version, since it's a very useful feature.

    We now can use something similar to the script TestDiceRegister.cs to check the results of dice that are spawned.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using DiceMaster;
    4.  
    5. /// <summary>
    6. /// Registers to spawned dice and logs their result
    7. /// </summary>
    8. public class TestSpawnRegister : MonoBehaviour {
    9.  
    10.     Spawner spawner;
    11.  
    12.     void Start () {
    13.         spawner = GetComponent<Spawner>();
    14.  
    15.         spawner.onSpawnDice.AddListener(this.OnNewDiceSpawned);
    16.     }
    17.  
    18.     void OnNewDiceSpawned(Dice dice)
    19.     {
    20.         dice.onShowNumber.AddListener(RegisterNumber);
    21.     }
    22.  
    23.     public void RegisterNumber(int number)
    24.     {
    25.         Debug.Log("Got " + number);
    26.     }
    27. }

    And that's it. Attach this script to a Spawner and it will detect when a new Dice is spawned, attach to its onShowNumber event, and let you do whatever you want with the resturned numbers!

    Thank you for your report and I hope you find the asset useful!
     

    Attached Files:

  12. Eggpunk

    Eggpunk

    Joined:
    Nov 2, 2014
    Posts:
    39
    Thanks, Catman! Those worked perfectly!

    I've been working to tally up the number of time each result occurs (one occurrence of 3, five occurrences of 1, etc) So that I can trigger events based on those results. Is that in line with the features discussed earlier with Duffer123? Or am I way off base?

    Also this asset has been super awesome. A lot of time and confusion saved over here, and the asset is still in beta. Awesome stuff.
     
  13. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Glad I could be of help!

    I'm not really sure I understood what you are trying to do. Are you just counting the results? If that's the case, it's outside of the scope of the tool (you could do anything with the returned number, just by creating something similar to TestDiceRegister, which for example just sums the totals).

    Duffer123 is talking instead about creating a spawner that directly gets dice strings such as "3D6" and throws three six-sided dice at once!
     
  14. Eggpunk

    Eggpunk

    Joined:
    Nov 2, 2014
    Posts:
    39
    I'm working on some code that counts the results this week myself. It's been a while since I did some coding last, but I'm almost at the results I want. I'll post some results here in case anyone comes by interested in the same result print out.

    I read too far in to the spawner discussion I think. I understand now, thanks.
     
  15. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Let me know if you find any more trouble!

    I guess what you would need is just something like:

    Code (CSharp):
    1. int counters[] = new int[6];
    2. public void RegisterNumber(int number)
    3. {
    4.    // Increase the i-1 counter (0 for 1, 1 for 2, ..., 5 for 6)
    5.    counters[number]++;
    6. }
     
  16. Eggpunk

    Eggpunk

    Joined:
    Nov 2, 2014
    Posts:
    39
    Hey Catman;


    I've been learning to code + working on my code all week. I've gotten close to the results I've been wanting but I'm suck on 2 final items for now.

    with the help of a friend and some internet goers plus your initial code, I made a list that maintains count of the 6 different possible results from my 6-sided test dice.

    When I press 'Play' the dice roll and the result of each die is tallied and added up properly. I added some if statements for each result so that new logs appear based on how many times each result occurs. After some tweaks, those now work properly as well.

    The 2 final issues have are:
    • I can't seem to keep the roll results between plays. Every time I run the game, the result counts all start back at 0 (I think I need to figure out serialization to fix this).
    • My current code is locked to 6 sided dice. I'm trying to find a way to make the list flexible so I can use the code for any size dice.
    I'll be working these two items this weekend and if I get either desired result, I'll update here.

    Thanks again for Dice Master.

    Code with notes thus far attached.
     

    Attached Files:

    Last edited: Nov 21, 2015
  17. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Unity serialization is a complex topic. Note that any MonoBehaviour value, regardless of serialization, will be reset to the initial values each time you exit play mode.
    To save your state, you should look at the PlayerPrefs class (to keep things simple), or use some additional hand-made XML serialization.


    That's because you are using separate variables for each number (resultOne, resultTwo, etc.).
    I see you also have the ResultCount dictionary, tho, and you could just use that. Instead of looping over 6 values when creating the dictionary, you can generalize that to N values, where N is the number of faces.

    Cheers,
    Michele
     
  18. Eggpunk

    Eggpunk

    Joined:
    Nov 2, 2014
    Posts:
    39
    Yeah, after spending the past week or so looking at serialization and Scriptable Objects and not really making a dent it surely looks like its time to go to PlayerPrefs. Maybe I can look at serializing and SOs again after getting the ground works implemented set the way I want before optimizing.

    I tried pulling the numberOfFaces from the prefab the script was connected to over the weekend, but that's probably another case of aiming to high for a first trial set up. I'll see about making some less complicated changes tonight.

    Thanks for the feedback Michele!
     
  19. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Yep, that's the correct way of doing it: the Dice prefab you spawn will have a DiceDefinition you can access through its 'definition' variable, and that has the numberOfFaces variable.

    Glad I could be of help, I hope the tool will be useful for you!
    If you want to help back I'd really appreciate if you took the time to write a short review on the asset store!
     
  20. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Dice Master is now out of beta. Thanks to all the beta testers for their feedback and support!

    Here is the changelog:

    v 1.0.3
    - better default sound effect
    - added complete instructions in the documentation
    - added a complete set of warnings to the code
    - out of BETA!

    v 1.0.2
    - added spawning event to the Spawner class. Added a new spawn test register scene and script.
    - fixed bug with asset store paths being wrong

    v 1.0.1
    - fixed bug with spawner and trigger-on-start
    - made coin less susceptible to falling by cut
     
  21. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,216
    @Catman,

    Have implemented the dice string parsing support?
     
  22. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Hello Duffer123. Not yet, I focused on bugfixes, warnings, and documentation. I intend to add that with another feature at the next update. I will provide an example where the spawner will allow you to pass to it a dice string and it will spawn the correct dice.
     
  23. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Hello people!

    I updated Dice Master to version 1.1.0 with new features!

    The major change in this version is the support for dynamic faces. This means you can now choose for sprites to be separated on the dice's face instead of being drawn over a texture. This allows you to control faces dynamically and do things such as:
    • Change faces at will, or in response to the dice coming to a rest
    • Add animations and other details to faces, for example by making them pulse
    • Add any gameobject to the faces, instead of just sprites



    You will also find two new example scenes which showcase dynamic faces, as well as three ready-made dynamic dice.

    As per the suggestion of @Duffer123, I added also an example scene with a custom spawner that accepts strings in the format of "2D6" or similar and spawns the relevant dice.

    In addition, various small bug fixes and improvements have been added.

    Here is the changelog:
    v 1.1.0
    - Dynamic faces completed
    - Added two new test scenes: ExampleDiceCustomFaces and ExampleDiceDynamicFaces
    - Updated docs and manual

    v 1.0.6
    - Refactored DiceConfig
    - Added 3 ready dynamic faces prefabs: Dynamic D2, Dynamic D6, Dynamic D12
    - Added example custom dice: CustomFaces D6

    v 1.0.5
    - Added dice strings format parser with test scene ExampleDiceSpawnFormat
    - Updated dice creator interface for dynamic faces

    v 1.0.4
    - Added face distance from center to the dice definitions, needed to reposition planes
    - Added all correct face distances
    - Note: weights are now also placed at that same distance
    - Added initial dynamic faces code
     
  24. achooley

    achooley

    Joined:
    Sep 6, 2013
    Posts:
    17
    Hi! Can i set finish dice value (face when animation finished?) I need functionality for roll dice with predicate value?
     
  25. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    If with your request you mean making the physics behave so to give you a specific number, I suggest you instead proceed differently, since the package uses physics to determine what number should appear.
    Basically, think of it as physics telling you what number you should use, and not the other way around.

    Your request is something I have been thinking about for a while, but it would be practically impossible to achieve a realistic animation while mantaining physics constraints, hence why I added the 'weighted dice' option, which allows you to attach weights to specific faces which will force the dice to increase drastically the probability of a specific number appearing.
    You can try using the weighted D6 to see how this works (it should almost always give you a 6 if dropped from high above!).

    You can find more information in the FAQ on the "how can I rig the dice" question:
    http://www.michelepirovano.com/dicemaster/DM_Documentation.html

    If you want to rig the dice dynamically (i.e. as you play), you can access the resulting dice's weights (they are invisible rigidbodies added to the dice itself) and modify those at runtime.

    I will be out in the following days, so I may not be able to answer before this saturday!
     
  26. achooley

    achooley

    Joined:
    Sep 6, 2013
    Posts:
    17
    Thx for answer!
     
  27. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,216
    @Catman ,
    Does this asset also JUST provide an integer value on parsing a dice roll string (just that functionality without the 3d dice etc)?
     
  28. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    If that is all you need, the asset is a bit overkill.
    Here is the code for what you need to do, taken from the asset. It's a really minor part, so feel free to use it.
    This code will take a dice string as input and detect how many dice to throw and with what faces (I.e: 5D2 would return 5 and 2).


    Code (CSharp):
    1.  void Interpret(string diceString)
    2.     {
    3.         int nThrown = 0;
    4.         int nFaces = 0;
    5.  
    6.         var numberStrings = diceString.Split('D');
    7.  
    8.         Debug.Assert(numberStrings.Length == 2, "Dice string is not in the correct format!");
    9.  
    10.         nThrown = int.Parse(numberStrings[0]);
    11.         nFaces = int.Parse(numberStrings[1]);
    12.  
    13.         StartCoroutine(SpawnCO(nThrown, nFaces));
    14.     }
    15.  
     
  29. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    If you actually just need to simulate the result of a dice throw, you can do so with the Random.Range method of Unity: Random.Range(0, numberOfFaces)+1 will return, for a D6, a number from 1 to 6, randomly.
     
  30. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,216
    Thanks Catman
     
  31. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    You are welcome!
     
  32. Infotaku

    Infotaku

    Joined:
    Apr 26, 2016
    Posts:
    1
    Not sure if this is the place to post this, but I found a little issue in the "D4 Default" texture.
    At the bottom you can see that there is an issue with the numbers. Some corners have different values.

    Great job on this btw, I'm having a blast !
     
  33. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Hello Infotaku, thank you very much, I am happy you found the package useful!

    Thank you very much for the bug report, indeed there was an issue with one of the faces for the standard D4 texture generation, I fixed it and the bugfix will be in the next update.

    I attached to this post the new generated texture for the default D4 for you to use, here it is:
    New D4.png
     
  34. CarterG81

    CarterG81

    Joined:
    Jul 25, 2013
    Posts:
    1,773
    I just purchased Dice Master for a 2D project (X/Y plane) and was wondering if there are any special considerations I need to know for rolling dice with the dice landing down on the Z plane, rather than gravity pushing them down on the Y.

    I still like the idea of dropping the dice downwards onto my Unity2D gameboard, having them react exactly the same, rolling around in 3D, but gravity being on Z instead of Y. Throwing them so they roll around X/Y, landing on Z=0, rather than X/Z landing on Y=0.

    Just modifying it to support Unity2D, rather than Unity3D.

    edit: Is it really as simple as just changing Unity's gravity Vector3?

    Code (csharp):
    1. Physics.gravity = new Vector3(0, 0, 1.0f);
    If this isn't a supported feature, I would like to make it a feature request (roll the dice in a Unity2D axis game).
     
    Last edited: Nov 24, 2017
  35. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Hi Carter,

    yes, the dice will work in 2D, they will consider the Physics.gravity to determine what is the face that is 'up', so it's as easy as changing the gravity as you said.

    In any case, I did not test it too much with 2D apart from that, so let me know if you encounter any issue!
     
    CarterG81 likes this.
  36. RoxieCotton

    RoxieCotton

    Joined:
    Jan 16, 2018
    Posts:
    4
    I'm so mega new at this, I recently downloaded your dice master, but even through the HTML guide and FAQ's I don't understand. I apologize in advance for the noobness. How do I spawn and toss dice onto the playmat, like a window off to the side with a list of dice and once selected press S to spawn a dice from where the mouse pointer is. Thank you in advance!
     
  37. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    What you need is a mix of different features to create a more complex behaviour, so you'll need a bit of scripting to do that.

    Let's take a look at the different steps:
    1. Have a window on the side (I assume the inspector) to select the dice and number of dices.
    2. Press a key to spawn the dice
    3. Place the dice where the mouse cursor is
    4. Throw the spawned dice
    You can proceed as follows for each step:
    1. The first step is quite easy, you just need a Spawner component attached to one empty GameObject in your scene. You will be able to then choose which dice to spawn and the number of dices to spawn. Note that if you instead need an interface inside your scene so that a user could choose the dice and number, you will need to write a script similar to the SpawnSelector, which shows how to create a small GUI that connects to a Spawner. Take a look at the ExampleDiceSpawnSelector selector for all of these in action.
    2. If you want to spawn the dice with a key, you will need a script similar to TestDiceSpawner. Take a look inside, it is very simple.
    3. Placing the dice where the mouse cursor is is a bit harder, as the default Spawner spawns at the position of its GameObject. You will need a new Spawner that extends the base one. I wrote a small script for that and you will find it attached here.
    4. Throwing the spawned dice is easy, you just need to make sure to attach a Thrower component to the Spawner and the Spawner will automatically use it to throw your dice
    To sum it up, here is how your spawner should be:
    You can see that I have selected a D6 Default to be spawned, and 1 of those will be spawned. When spawned, the dice will be thrown in the direction (0,-1,0).

    upload_2018-1-22_10-4-41.png
     

    Attached Files:

  38. JeepTX

    JeepTX

    Joined:
    Sep 16, 2017
    Posts:
    4
  39. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Hello JeepTX. The package you are referring to seems to include, alongside the dice mashes, a custom material with many parameters for customization. Are you referring to that? If so, the answer is yes, you could use the dice that come with that asset and use the scripts that come with Dice Master to control them, you'd just need to replace the graphics assets with those.
     
  40. enajhernandez01

    enajhernandez01

    Joined:
    Nov 6, 2017
    Posts:
    7
    hi i just want to ask if you have some free assets of this one coz i can't afford to buy. Thanks. :)
     
  41. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    I'm sorry but I'm not giving out free assets, it would not be fair to those that buy it. You can check out the store for similar free options.
     
  42. PhilFischer

    PhilFischer

    Joined:
    Dec 29, 2017
    Posts:
    2
    I'm curious if your dice roller can do the following:

    a) I need to be able to roll small (12mm) and large (16mm) dice at the same time.
    b) I also need to be able to roll multiple colors at the same time.

    c) i.e. 3 small lavender dice, 2 large lavender and 4 large green with 2 small green; all at the same time.

    Can your dice roller do this?
     
  43. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Hello Phil,

    Yes, you can roll any number of dice, of course there is a large enough limit tied to graphics resources.
    You may do that out of the box by creating several dice spawners+rollers, each with the different colored /sized dice, and trigger the one you need based on your game's triggers.

    However, if you are so inclined, I'd suggest you write a few lines to extend the dice selector example so you can define which dice to spawn using a single spawner+roller instead of several. Take a look at the ExampleDiceSpawnSelector scene inside the asset pack.
     
  44. PhilFischer

    PhilFischer

    Joined:
    Dec 29, 2017
    Posts:
    2
    That's awesome, thanks much - Phil
     
  45. TekAgeS

    TekAgeS

    Joined:
    Jun 5, 2018
    Posts:
    2
    Really nice package. Purchased it this past weekend and the only thing I'm having issues with is a "hard roll". I'm using the limits but some dice manage to "push through". I've tried adjusting things like collision - Continuous, Cont-Dynamic, but they still seem to smash through the limits planes. Any ideas?
     
  46. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Hello TekAgeS, thanks for purchasing DiceMaster.
    If you need to throw really fast dice, a good idea can be to replace the PlaneCollider limits with BoxCollider limits. Think of them as invisible walls. With a wide enough BoxCollider, you should not have issues with dice passing throught.

    Let me know if this is of any help.
     
  47. TekAgeS

    TekAgeS

    Joined:
    Jun 5, 2018
    Posts:
    2
    That really worked well. How do we change the color of the dice?
     
  48. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Glad it helped. You can color dice by changing their base texture, check out the Dice Creator system. You can find more information in the documentation here under "Creating new dice".
     
  49. nguyenman999

    nguyenman999

    Joined:
    May 5, 2017
    Posts:
    1
    Hi! I have bought this package last week and also read through all the documents but I can't find any help to throw the dices with the predicted result. The weight value does not work as expected. Could you pls help me?
     
  50. Catman

    Catman

    Joined:
    Jul 16, 2011
    Posts:
    47
    Hello, as previously stated in this thread, Dice Master uses physics to determine what number should appear and not the other way around. Unfortunately, this means that there is no sure way to make the dice report the number you want prior to throwing it.

    It would be practically impossible to achieve a realistic animation while mantaining physics constraints, hence why I added the 'weighted dice' option, which allows you to attach weights to specific faces which will force the dice to increase drastically the probability of a specific number appearing.
    You can try using the weighted D6 to see how this works (it should almost always give you a 6 if dropped from high above!).

    This won't be 100% accurate, but if you give the dice enough space to fall and roll, it should work most of the time.

    You can find more information in the FAQ on the "how can I rig the dice" question:
    http://www.michelepirovano.com/dicemaster/DM_Documentation.html

    On the other hand, if you just want to show the result, you can always rotate by code the dice so it shows the correct number, then drop it down so Dice Master registers the result when the movement stops.