Cameron Main


← Back to Projects

Dice Roller Prototype


A Unity-based turn-based dice roller inspired by Yahtzee.

Dice Roller gameplay Dice rolling and scoring in action.

Key Features


Description


I had the idea for this spinning around in my head for a while and finally scratched the itch to make a fun prototype of it in Unity. The premise stems off trying to achieve crazy combos and attaining as high a score as you can by matching & combining dice patterns typically found in the game Yahtzee.

Dice patterns
Dice patterns and associated scores.
Mid-roll gameplay
Mid-roll gameplay.

Dice Combinations and Scoring


Combination Description Points Multiplier
PAIR2 dice of the same value+20+2x
TWO PAIR2 sets of 2 dice with the same value+25+3x
TRIPLE3 dice of the same value+30+4x
TWO TRIPLES2 sets of 3 dice with the same value+45+8x
FULL HOUSE3 of one value and 2 of another+35+5x
4 OF A KIND4 dice of the same value+35+6x
5 OF A KIND5 dice of the same value+45+8x
6 OF A KIND6 dice of the same value+70+16x
STRAIGHTAll 6 dice have different values+50+10x

For example, if a player rolls: 3, 3, 3, 4, 4, 6

This roll contains:

The score would be calculated as follows:

  1. Base score from combinations: 30 + 20 = 50 points
  2. Sum of dice face values: 3 + 3 + 3 + 4 + 4 + 6 = 23 points
  3. Total base score: 50 + 23 = 73 points
  4. Total multiplier: 4 + 2 = 6x
  5. Final score: 73 * 6 = 438 points

This score of 438 points would then be dealt as damage to the enemy.

The higher the score generated, the more damage dealt to the opposing enemy. Players can choose to gamble by rerolling, in the hopes of obtaining a die to make a higher-tiered combination, thus dealing more damage to their opponent.

The gameplay loop works via turn-based combat in which the player has a limited number of rerolls, but can gain an extra roll per enemy kill. At the end of the turn, the score generated is dealt to the enemy as damage. The enemy will then retaliate with an attack of their own (if still alive). This repeats until all enemies are defeated or the player loses all their health.

Balancing Probabilities and Points


An essential aspect of the game's design is balancing the points based on the probability of achieving different patterns. To ensure fair and engaging gameplay, I developed a Python script to simulate dice rolls and calculate the probabilities of each pattern occurring within a given number of rolls.

This simulation helped me make informed decisions about adjusting the scoring system:

Technical Challenges


One challenge I faced was determining which face of each die was facing up to attribute the correct score. While this task is straightforward for humans, implementing it in code proved to be an interesting challenge. I solved this by using a trigger collider on each face of the dice and a face detector script attached to the floor where the dice land. Once a die's velocity settles and it comes to rest, the detector activates and determines which collider it contacts. Each face is mapped to a corresponding trigger collider, returning a value attributed to the die object.

Using colliders works well for this small prototype, but a more performant method would map the rotation values of the dice to associated face values and check the die's current rotation when stationary. I initially attempted this approach, but for whatever reason the results lacked consistency. Considering the time constraints of a prototype, I decided to move away from this method and instead employ the aforementioned approach.

These adjustments helped create a more balanced and rewarding gameplay experience, encouraging players to aim for rarer patterns while still valuing more common combinations.

Tools Used


C# Unity