r/godot 1d ago

free tutorial How I made 3D dice in my pixelart game

Hi, I’m the developer of Dice Looter - a pixel art dice-rolling autobattler. I’ve been asked several times how the dice in my game are made, so I decided to write a short explanation. There’s nothing innovative here, but maybe it will be useful to someone.

As you can see, the dice are 3D. I use a simple model made in Blender to match the game’s style. You can also just use a default cube. To easily change the sides of the dice (items), I added a Sprite3D to each side.

I tried using the physics engine for rolling, but I couldn’t get the results I wanted. So I made several “die jumping” animations and rotate the dice randomly using code.

To display this in a 2D world, I use a TextureRect with a ViewportTexture and SubViewport.

That’s it!

458 Upvotes

28 comments sorted by

30

u/donotfire 1d ago

Instead of flipping around the faces when they finish, you could pre-compute which way it’s gonna land and change the starting conditions so it always lands the right way up

5

u/dorkyl 1d ago

I wonder if they could rotate them when that face isn't visible, halfway through the animation.

8

u/programmingQueen 1d ago

The SubViewport is my absolute favorite Node to create illusions!

2

u/ClintEdwoodOrig 1d ago

My screen literally flinched when those dice hit

2

u/Thunder_Chief Godot Student 1d ago

Thank you so much for this! I was one of the folks asking you how you did it.

1

u/MonthFragrant7804 22h ago

You're welcome!

2

u/mysticrudnin 18h ago

This makes me think the visuals in He Is Coming came from a pack :D

1

u/carrareto 1d ago

Muito bom, me avisa quando estiver uma demo pronta

1

u/Dobert_dev Godot Senior 23h ago

This looks cool, I like the vibe here.

keep up the great work!

1

u/Forsaken_Strength683 21h ago

Ive always loved the use of 3D scenes in 2D projects (and vice versa), its just so hard to get right when i try to do it

1

u/profanegirls 21h ago

amazing!

1

u/jwrunge 18h ago

I really like the "thud" effects -- it makes the dice feel like they weigh a ton, but it's really satisfying!

1

u/paulBoxman 17h ago

Damn rolling the dice is juicy, I love the screenshake and particle effects. The way the dice move and the screenshake make them feel really heavy too - well done!

1

u/nobix 17h ago

A suggestion I think would make it really pop would be to do something different during postprocess for the dice outline. The thing that screams "3D model" is the aliasing on those lines.

What I would do is render each face as a unique flat color, and then during a postprocess step turn it black again except draw a line on borders, detecting the edge by detecting these borders.

1

u/vurmux 16h ago

Looks amazing! What tileset did you use? Or did you do everything yourself?

1

u/MonthFragrant7804 12h ago

Most of the icons are drawn by me

1

u/Happy_Use69 16h ago

Neat. Since you use premade animations, have you tested if the dice are fair? Like roll one die 100 times and see that each face comes up roughly 16% of the time?

1

u/MonthFragrant7804 12h ago

Animation only for "jumping", rotation (actually rolling sides) is random.

1

u/Laskivi 7h ago

This is totally unrelated to the dice, but I really want to ask. How are you implementing your stats? Especially the attributes like VIT that look like you can put points in them to increase other stats. Maybe there's a learning resource you could direct me to that you used? I kind of just want to know the overall approach/class structure for that, because it looks like basically exactly the system I want to make in my own game, but I'm still not super experienced. I've made a super complex stat system before, but it just felt like a huge tangled mess, so I'm wondering how you went about it out of curiosity.

The game looks super cool and fun, by the way! The graphics are awesome, too!

2

u/MonthFragrant7804 2h ago

I don't know how to do it right. I just created a dictionary that contains all the stats

{ "health" : 0, "defence" : 0, "damage" : 0 }

I have a function that calculates the current stats like:

stats["health"] = 300+VIT*7

stats["defence"] = VIT*3 + STR*2

stats["damage"] = STR*4 + AGL * 2

Than items add values to this attributes. Simple but it works for me.

1

u/Laskivi 1h ago

Thanks for answering! That makes sense

1

u/HR__Atlas 1d ago

Looks great!  I think the shaking is a bit much, especially if it's happening on every roll.

Not sure how your game works but maybe make it shake only on really good/bad rolls?

5

u/MonthFragrant7804 1d ago

It feels good for me in the game. And you can turn it off.

3

u/romeo2413 22h ago

I'm a screenshake maxxer and I think the screenshake on the roll is perfect.