 Okay, today is less of a tutorial and more of just practicing my skills and sharing that with you. We're going to make a simple little application where you can roll dice and get random numbers. We'll be able to roll multiple dice or a die or multiple dice as we go along. So let's go ahead and get started. I've created a new project in Godot here. I'm going to choose a 3D scene. I'm just going to call this main or whatever I want to call it. Let's go ahead and add a ground plane for it. Right click. Add child mesh and we're going to choose mesh instance. We're going to create that. We're going to set it to a plane. Again, I'm going kind of fast because it's more of a demonstration than a tutorial. We're going to make it 50 wide and 50 long. So X and Z. And then we're going to right click this or not right click it, but left click it and say create tri mesh from static body that gives us a collision shape for the ground plane. In fact, we'll call this ground just so we know. Next I will create or I've already created. I've been working if you've been watching my videos, I've been working on an asset pack for games. I've been working on a bunch of 3D models amongst other things. So let's go ahead and grab a 3D die that I've created. So get lab my projects and it's called game assets and under collection one under GLB, you'll be able to find one called die. We'll click that click here and we will save it right in the same directory as our project. It's a bigger project. I'd make a separate folder for the models, but it's going to be the only model in there. Going back to our game here, it has been imported now. Let's go ahead and create a new scene because I want to be able to instance this dice, meaning making multiple copies of it so we can again roll one die to dice, three dice, however many we want and I'm not, what am I doing? I want to create a new scene, scene, new scene. And we're going to say 3D, we'll call this die. And we will drag in our dice model here. There it is. We'll go ahead and leave it just like that. Actually let's go ahead and make local and that way I can just drag the model up here and delete this. Probably could have just opened up the GLB file as a scene, but I'm going to save this as dice scene and I'm going to save this as our main scene and then if I hit F5 here, it's going to ask me what scene I want to be my default, I will choose main and we will see nothing at this point because we have to add a camera and the dice. Right now we just have the ground plane, so I'm going to right click this, I'm going to add a child, I'm going to call it, or call it, I'm going to find a camera, so there we have our camera. I'm going to back that up and move it up and now I can right click this and say add an instance and I'm going to say dice or die. Here's our die. Great. We're actually going to change a few things in our dice scene here. We're going to change the main type of this. Let's change the type to a rigid body and a rigid body is going to need a collision shape. So we can do this a few different ways. We can go mesh and add trimesh, but that might add more than we need. Let's go ahead and just, you know, let's just do that. It's the simplest way. That's no, that's a lot of collision shape we don't need. Let's go ahead and we'll attach a note and we'll say collision. So basically that's taking our mesh and adding a collision shape in that exact shape. We don't want it to worry about all the holes or even those curved edges. We just want a simple box put around our model here. So I'm going to say new box shape. So collision shape, box shape. Let's put our cube inside there and at this point we're going to resize it. We're going to say transform. Now we're going to resize the collision shape which will also resize its child. You do not want to resize the rigid body because that will mess up the way it bounces around. Let's say 1.1.1.1.1 and now we have a little die. Save that. Come back here. There's our die and we can drag that up. If we hit F5 now it will start our game and our die should fall boom and bounce around. Let's go ahead and start scripting stuff out so that the camera follows that die. So let's go ahead and just go to our main here and we're going to say attach a script main that's fine and really the only thing that's going to do is over and over again it's going to tell the camera to look at the die. So we're going to say dollar sign camera dot look at and in here we need to give it the position of our die which is going to constantly be updating. So we're going to say dollar sign die and we're going to say dot and how do we get its position? Global underscore transform which gives us basically its size and position and then we just do dot origin to get just its origin. The other thing we need to pass look at is which direction is up so we're going to pass it a vector 3D or a vector 3 and we're going to say 0 comma 1 comma 0. So we're just saying here that y is up. Now if we hit F5 we watched our die fall and roll over. We'll hit a 5 again, start it again, our die falls and rolls over. You see it does the same exact thing every time. We don't want that. We want it to be random kind of the point of having a dice to roll right. So in here we're going to right click and we're going to attach a script and we'll call it die that's fine. And so what is our dice? We're going to want to start it off at a random position and we also want to rotate it give it a velocity to rotate at a random rate. So in here we're going to say under its ready function first of all we want to make sure that we set randomize so that it starts generating random seeds. And we're going to say var for x equals we're going to give it a random range. And we're going to say from negative 10 to 10. Now I grab those values just add the error but they seem to work well. I'm going from a negative number to a positive number in the same direction or same amount so that sometimes it might spin clockwise or counterclockwise on each axis. So oops I'm going to copy that paste, paste, paste but change this to y and z. And then we're also going to say rotate vector 3 comma and we'll create another variable called r. So what is this doing? So r will be for rotate so it will start off at a random position. There needs to be brackets in here or parentheses. So that's great. So it's starting at a random position which right now if we just start it off it will roll to a different number each time because it should be starting off in a random position theoretically. It looks like it did the same thing. Maybe my rotate function isn't working. I thought that would work. That's not so important. Let's just get rid of that. The main important thing is the velocity. So we're going to set our angular velocity. Why is it not auto-completing for me? That means I'm doing something wrong. We're doing this under the rigid body, right? Yeah, angular velocity. Okay. I have no clue why it's not auto-completing. Set angular. Just got to make sure I'm spelling things right. And we will give it a vector 3 of x comma y comma z. Those will be our random numbers that we generated. So that should start it spinning at a random velocity in all three directions. So let's see what happens. Yeah, it's working. I just don't know why it wasn't auto-completing for me. Let's go ahead and go to our 3D scene here. Drag that up a little higher. At five, let's have a look again. Okay. Let's see if we can affect, let's say it's gravity or weight, mass. Let's go mass. Do we want heavier or lighter? It just seems to be falling a little fast. It's a little better. Let's go gravity scale 0.5. Now I'm just playing around, trying to get the animation to look real. That's much, much better right there. Okay. And now one more thing we'll want to do is under our main script here, we're just going to say function input event. We're going to say if input and we'll say is mouse button press. We'll say mouse button one, which is your left mouse button. Then we're going to, I believe it's get node dot get scene. I actually know it's not get node, it's get tree. That reload current scene. So every time we click the mouse, it will reload the scene. So basically you're re-rolling the dice. Let's go ahead and make this full screen. There we go. We got three. This time we got three again, but definitely rolled differently. Three again, four, three, six, okay. So we're getting random things here. Now what we can do is in our scene here, if we would like, we can control D, move that up a little bit, control D, move that up a little bit, control D, move that up a little bit. And now we're rolling four dice. Now a little wider here. Right now, I'm not going to change this for this little exercise. We're following that first die. So other dice might roll out of your view here. Let me click again. It's going to be a little different each time. That time it didn't. But what you could do, there are ways to calculate the center point between all four of the dice or however many dice you have, and have the camera focus at the center of all of them so that you don't have any dice rolling out. And occasionally you have one die falling out of there. When you stack them straight up like I'm doing, it doesn't happen all that often. But there you go. Very basic exercise for rolling dice in Godot. Again, this code will be up on GitLab. Check out the links in the description of the video for that and to my Game Assets project where I'm constantly making new models and other Game Assets that are free for you to download and use. So enjoy. Visit FilmsByChris.com. That's Chris of the K. And I hope that you have a great day.