Dice Roller Package

In the new Table Top Champs season we added a bunch of dice meshes for you to use in your board game creations. This package allows you to have the dice be spawned and launched into the air (effectively doing a dice roll.) before landing on the terrain in a semi-random order. There is also a few utility scripts that will work out the total on each dice for the 6-sided die type. basically it looks at what face is pointing up and should correctly score them.

Installation

Search the Community tab for ‘Dice Roller Package’ and install the package.

Usage

To get the basic dice rolling effect all you need to do is drag out the dice roller template. You will need some sort of trigger or event to run the appropriate function. I suggest also pulling in the dice roller example and then in the trigger that this template contains make sure to link the entity to your ‘diceRoller’ entity and check the ‘diceRollerScript’ is the active script and that the Active() function is called.

To get the scoring for the total dice scores working you also need to drag in the diceWatcher template. But, each dice will show their current score out the box if you use the 6-sided dice type.

Steps

  1. Install the package
  2. In Templates find the ‘Dice-Roller-Example’ and drag into the world away from your player start point.
  3. In Templates find the ‘DiceRoller’ and drag into the world, place it away from the spawn point for your player and the Dice-Roller-Example template.
  4. Expand the ‘dice-Roller-Example’ in the World tree so your see the ‘RollDiceTrigger’
  5. Select the ‘RollDiceTrigger’ and expand the event OnTriggerEnter
  6. Drag ‘diceRoller’ from the world hierarchy to the Entity slot this should remove the error from this template.
  7. Preview the game and stand on the platform mesh to activate the dice roll.

Templates

  • D6WhiteTemplate - The 6-sided dice mesh turned into a spawnable template, this also has the dieDisplay and dieWidget attached for individual scoring, as well as a trigger to detect when the dice has landed.
  • D12BlackTemplate - The 12 sided black dice mesh that has been made into a template, you could add this to your diceRoller script as a spawnable dice type - it’s more there as an example of how to create your own dice templates for spawning.
  • D12BlueTemplate - The 12 sided blue dice mesh that has been made into a template, you could add this to your diceRoller script as a spawnable dice type - it’s more there as an example of how to create your own dice templates for spawning.
  • Dice-Roller-Example - This has a trigger on it that can be used to trigger the dice rolling. Not very useful in most cases, but there so you can quickly setup an example scene to test out the package.
  • DiceRoller - This effectively contains the DiceRollerScript which is explained in more detail below.
  • DiceWatcher - This effectively contains the DiceWatcherScript which is explained in more detail below.
  • DieDisplay - Contains the widget that will be displayed above the 6-sided die when the scoring happens.

Scripts

  • diceRollerScript - spawns and launches the dice to ‘roll’ them, there are quite a few customisable options in terms of adding more dice types to spawn and visual and audible effects when you launch the dice.
  • diceWatcherScript - Effectively a utility script, it will watch for the dice landing and settling then tell you the overall score. This currently just prints to a log, but you could access this script to do something like print the values on an on-screen UI.
  • dieLogicScript - This has a few uses, one that it will play a sound if the dice collides with something. The other is that for a 6 sided dice it will do some vector/dot product logic to find what direction the dice is facing when it lands and works out what number is on the top face.
  • dieWidget - This is the UI script used to display the scores above individual die.

Script Properties

diceRollerScript:

  • Spawn - An array that can have templated dice placed in it (or anything else.) these will be the entities spawned when you trigger the Active() function to roll them.
  • SpawnAmount - How many individual dice should be spawned by the script.
  • DelaySpawn - How long to wait until the spawn happens from calling Active() function.
  • SpawnSound - The sound to play when the dice first spawn.
  • SpawnEffect - The effect to play when the dice spawn.
  • EffectLocator - Place that the effect should spawn if you don’t want the effect to spawn at the placement of the DiceRoller template in your world.
  • DelayEffect - Delay the effect until after the sound has played.

dieLogicScript:

  • CollisionSound - Sound to play when your die hits a surface, this is handled by a collider.
  • WidgetReference - Widget that should be access to display the appropriate score.