Godot 3.1: Creating a Simple 3D Game: Part 3 (Importing from Blender, Rolling & Keys) #GodotEngine

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Fantastic video - can't wait for the rest of them to come out.... you can't get done with this series soon enough.

Love how you cracked the method for getting objects from Blender to Godot with the cycles materials - this is what basically stopped me from playing with Godot late in 2018; the process used to be way too cumbersome.

I made a version with a skull and another with Suzanne rolling around instead of the ball.

I am subscribed and clicked the bell. Keep up the good work!

👍︎︎ 2 👤︎︎ u/Briaxe 📅︎︎ May 30 2019 🗫︎ replies

Although 3D is not really my focus, I have to say I'm enjoying this series. It's very well done and I'm looking forward to the next :)

Also, for the rotations, I believe you can get accurate rotation results by rotating the ball locally around the axis perpendicular to its motion vector, V, in the x-z plane (i.e., rotate around (-V.z, V.x).normalized()). It seems the rotate(axis, angle) method fits the bill. I'm not all too familiar with the 3D side of Godot, but I think this would work nicely.

As for calculating the angle parameter's value, first divide its linear speed - the magnitude of the motion vector in x-z - by 2 * PI * sphere's radius, which will give you how many revolutions/sec the ball is experiencing, in that direction. Then you can convert that to radians by multiplying by 2 * PI. Finally, you multiply by delta to get the per-frame rotation. This simplifies to: rotation per frame (in radians) = speed / radius * delta. I'm not completely certain of the angle sign, since the motion of the ball in the video is based on restricted directions, and the speed is simply inverted based on the axis direction for each of the x- and z-axes. That being said, it seems that negative angles correspond to clockwise rotation around the axis perpendicular to the direction of travel, which is what you would observe if you were to roll a ball and you were observing it from the side; it would appear to be rotating clockwise as it rolled forward (like when the ball rolls to the right in the video).

👍︎︎ 1 👤︎︎ u/Vortexspherex 📅︎︎ Jun 03 2019 🗫︎ replies

These are amazing videos, please keep the series going!

👍︎︎ 1 👤︎︎ u/[deleted] 📅︎︎ Jun 07 2019 🗫︎ replies
Captions
hello and ibaka part three of creating a simple 3d moving dodge game using the cadeau game engine my name is Colin and in this video series in about twelve videos we're gonna be creating this simple 3d moving dodge game you play by being a ball that you roll around a 3d maze in the game you collect coins you avoid rolling enemies and if you collect all the coins you win and go to the you wooden screen and if you hit an enemy you go to the game over screen and then you can go back to menu and try again so in this video we're gonna go over a few things specifically or we're look at how to get a model and its material from blender 2.8 in to Godot so the export process and settings that you'll need to change in order to make that work we're also going to add simple materials to mesh objects in Godot that we made in the dough and we just want to add a material to it so materials in Godot we're also gonna add a rotation to our ball so when you move the character the ball in the game it actually rotates in the right directions so we'll go over that and last but not least I promised us in the last video I think but I didn't include it we're gonna learn how to change actions that means that we can not only move our character using the arrow keys on our keyboard but we'll be able to move them with whatever Keys we want like the W a s and D keys the directional letter keys on the keyboard but this is a part three in this miniseries if you've not seen part 1 and part 2 if you have not seen those I'll put a link to my cadeau 3-story l series on the screen right now so you can go ahead and check that out if you haven't seen the first two parts also of course if you'd like this video for learn something go ahead and click on that like button below this video on YouTube it really helps me out and if you want to see more videos like this one in Godot or blender and tech click on that subscribe button as well and click the bell icon to be notified whenever I upload a new tutorial so let's go ahead and jump in the first thing I'm gonna do is show you the model that I'm actually giving you a link to download the blend file for a blender 2.8 in the description area below the file is right here it's called player ball dot blend it's a blender 2.8 file if you're in the future july 2019 or later if you go to blender.org you couldn't get most likely by that time july 2019 plunder 2.8 will be a stable release and so that will be the new version of thunder up until now though it's just in beta so on my desktop here I have the portable beta version of blender 2.8 so I'm gonna go ahead and open it up and if you've not seen 2.8 this is what it looks like a little bit different than 2.7 in the past so let's go ahead and check this out I'm gonna go to file and open go to my desktop I've got a file here called player ball top blend that you've seen already if I open it up this is what we get this is my character it's a simple ball it's really just a sphere we're going easy here and the sphere in the right hand side properties editor under the little ball material tab it has one simple material that I have named a luxo material like the lux football from the Pixar shorts and movies and that one symbol material just has three nodes if you're familiar with nodes in blender their way of building a material up and making very complex materials although this is really not much more than the basic material that you would add to any object in learned 2.8 except besides just having a principle be SDF material it has an image texture plugged into instead of using a simple base color it has a picture instead and that's this picture over here if I go to the 3d editor window and press tab with the ball selected I can go into edit mode and you can see all the edges and vertices and faces and you can also see because I have it all selected I press alt a it'll deselect or a to select in edit mode you can see all of the vertices up here but you'll also notice that I made a seam around the equator essentially of this model and that's because or you can see that if I press alt a it's red so that's where it gets split up this is a UV map you lay out up here and so it works and this image file is actually packed into this blender file so if you get the blender file you have access to the image file as well so this is our model the one thing I'll say here is that I do not have any cameras or lamps or anything else in this file if you do that might make things a little bit more complicated but we'll talk about that in a moment the other thing that you need to do if you're taking a model from blender to Godot is make sure you name your materials very uniquely if you bring in two different objects from blender into Godot and they both have the default lazy material dot zero zero one material name and then you're gonna run into problems because Godot is gonna recognize that they have the same material from two different files perhaps and it's gonna give both your models the same material I wouldn't also go to complex on your node setup this is a very basic node up in blender you can make lots of crazy materials by combining tons of different nodes I don't know how well cadeau would handle that so that being said if we go up to file and export with the ball selected there are many export options and the most popular kind of file that you need to export in many cases it's called a Claddagh file a Claddagh file is a dot Dae file and that is the most mature out of any of these file types to get to Godot but most people recommend that you use a different exporter it's an add-on for blender called the better colada exporter but we're not gonna be using that why because I don't want to go through the pecci process of installing an add-on especially because I'm not using an installed version of blender it's the beta and a folder on my desktop so instead we're gonna use a newer kind of file type under file export called GL tf2 and this is a new kind of file that Godot will read and it's new to blender 2.8 let's go ahead and click on that option and you can see this is a save editor here so I'm gonna go on my desktop and I'm going to name this player ball but over on the bottom left there are some settings and if I make this a bit wider you can see the little bit better there are tabs for different pages of settings and you really have to be careful here not changed wrong ones everything is almost good by default except that we want to change the format from GLB to gltf embedded I found that that one works really well I'm not too sure about the others but this one does definitely work that's a very important setting to change the other one that you might want to select is selected objects if you have other things in your scene and you just want to export one object okay that could also be if you have cameras and lamps in your scene and you don't want to select those too okay so on my desktop I'm saving a gltf file and it's called player ball and I'll click export gltf and we're done in blender so I'm gonna minimize that and open up Godot on my desktop and let's go ahead and open up our game project and of course because now we have a character scene in our assets folder called stevie SCM we're going to look at that but first let's go ahead and look at level TSE Ensor main level in our game so we have our Steve instance right there if I select Steve over here in the scene dock we can select him what I need to do here is actually going to Steve's scene and change the mesh before I do any of that though I actually need to bring that gltf file into my project folder it's not and I've got an assets folder for all the objects that I create a Supper scenes in my game but I got make a new folder now so I'm gonna right click on this word res I'm gonna say new folder and I'm gonna make a new folder called imports okay you could name this whatever you want but I think that makes sense that I'm gonna press ok so now that imports folder I'm going to minimize Godot and just inside windows I'm gonna go to my project folder and now you can see I have a folder called imports not dot import but imports and I'm gonna go into it and this is my player ball dot gltf that I just explored from blunder I'm just gonna drag that in there and I'll close this now and go back into Godot and do you see it there was actually really quickly a little scroll bar dialog box or a progress bar on me like box and that was it quickly importing the model file if I go to my file system dock at the bottom left and I go into imports you can see there's a player boat gltf and a luxo material dot material this is a material resource and that's what it was doing when it was importing it was taking the embedded material in the gltf file and making into a separate Godot material for us now if I double-click on player ball gltf it will ask me scene player ball gltf was automatically imported so it can't be modified to make changes to it a new inherited scene can be created what is it saying here well a gltf file when Godot imports it it considers it its own scene which is good usually because you want to make a character like this or an object its own scene usually in Godot we learn that in the last video but it's directing us to a select and this is the default new inherited and I would not recommend that I would just go ahead and say open anyways and the reason for that is when you use open anyways it'll open up this gltf file as a scene like a tab at the top and it'll make it look like a scene it'll have a default spatial node and a mesh node for our mesh and we can see it and Godot here but if you were to I'm gonna go back with a little bit if you were to double-click on player bowl but gltf and select new inherited the things that are inside the scene will all be grayed out and that causes more headaches and it's worth so I'm going to close that by the way you could actually just drag in the model but again I wouldn't recommend that either there are better ways of doing it and that this is a messy way so let's go ahead and press control Z I'm gonna double click on player ball gltf click on open anyway and right away I'm gonna save as this scene so scene save scene as to make a new copy of it as a kind of a file a t sen file that we can actually edit in Godot you can't actually edit a gltf file so I'm gonna save scene ass and I'm gonna go out of my imports folder so I'll click the up arrow and go into mine assets folder and I'm gonna name this player ball dot T SCM now we're actually not gonna use the scene file I'll show you why in a moment but what we're doing right now is what you would normally do in order to get an object from blender into Godot and make it its own scene so you could then instance that object in any level or or scene in your game that you want we're in a little bit of a different situation though we already have a Steve CNN a Steve object that's instanced into our main level already so all I want to do actually is get the raw mesh and take it from this new player ball dot scene and bring it into our Steve scene so we're not gonna actually use this very much but I'm gonna save it in my assets folder anyways now one thing that you might have done before clicking on player ball gltf is you might have selected it down here and go out to import and changed a few settings especially the root node type which by default is spatial if you go and look at this player ball seem a root node is a spatial but if you're familiar with Godot enough to know that a character object is going to be a kinematic body then you can change that the import behavior of this gltf file if you select it again go to import you can change it to whatever know type you want in this case I'm going to click there and search for kinematic body 3d not the 2d one and click on create and then I can say rien port and that's something I might have done before I saved player ball dot CSC N instead though I'm gonna go to scene in player ball and right-click on this spatial node and I'm gonna say change type and that's just as easy to do and I'm gonna select kinematic body by just searching for it there we go so now our route of this new player scene is kinematic body now it also needs besides a mesh it needs what's the little air it needs a collision shape or a collision polygon so I'm gonna click on the route and I'm going to press the plus we're going to type in to the search bar called the shape and we're gonna use a 3d one not the 2d one of course so put on a 3d one and the shape needs to know its shape so I'm gonna select it and go over to my inspector and select a box shape just like we did it in the last video but again I'm actually not gonna use this scene instead we're gonna steal the mesh from this mesh node right up here if I select the mesh node you can see this mesh is over here I'm gonna save this scene first though now what I can do is look at this resource of this mesh node and I can save this resource into my project folder and then steal it or reuse it in my original character scene so I'm gonna click on this little arrow and I'm gonna say save I'm gonna save this resource so I'm gonna go to my assets folder I think I need to that's okay and this is gonna be called player ball dot TR es this is a resource file in Godot 3 so I'll click Save okay so following me here I'm gonna close this scene now we're not gonna use it although you could use this if you hadn't already made a character you could instance this in your level I could go to link or create new instance and I could make an instance of player Bella gltf or pardon me the player Balti SCN we don't want to use that gltf anymore and I could press open and I could have the ball but instead we're gonna update our one that has the code on it so why not go to Steve which has the script on it from before and I'm gonna go back to my three scene and I'm gonna go into Steve's scene and here Steve is a kinematic body he has a collision shape which is a box and he has a mesh which in the last video I just made from a default primitive sphere up here with the mesh selected I just before it had nothing I went I'll go to clear I just went to a new sphere mesh instead I'm gonna go to load and now I can select from my assets folder that TR es file of my luxo ball player mesh so I'm gonna click open with it select and there we go there is the ball and as you can see if I go to my front orthographic view you can see it's the exact same size as it was because that's how I planned it from blender and if it wasn't that could change the scale the geometry I think or transform pardon me I could change the scale over here but it's good so I can save this ctrl s I can go back to my level there is my ball if I press the play scene button I can play my game and it works just like before I can move my character around I can even push the box that's a rigid body off the edge of my platform so I'm good so that's bringing a mesh using a gltf file from blur point 8 into the dough let's quickly talk about materials I'm going to select my floor we're gonna add a color to my floor it's just got no material on it right now my floor I got has three parts it's a static body it has a collision shape a big rectangle force field and a mesh instance and the mesh instance is just a stretched simple cube or box mesh but if I select that mesh instance in my main level scene I can go over and look at it in the inspector and if I actually just click on its little thumbnail it'll expand information about it including a material slot and it's empty right now it has no material so what I can do is I can click on the little arrow next to it and I can say a new shader no no no we're not going to use shaders shaders are more complex materials that you can actually code and use no setups but we're just going to use a spatial material a spatial material is much more what you're expecting if you just want to change the color of a objects material so a new spatial material and there's a preview of it if I click on this little icon we're gonna kind of go to the next page in this window we have little back and forward buttons like a web browser but this is the page that shows us all the options for the material there are a lot here if you're looking for color the property you're looking for or the heading is called albedo albedo basically means the color of reflected light coming off of an object so I'm gonna expand the albedo section out I'm going to select the color just by clicking on the white box we're gonna make the color of the ground oh I don't know green okay and then I can just click somewhere to get rid of that color picker and as you can see it's green it looks kind of blue kind of like everything else because our sky is blue we'll talk about how to fix that in an upcoming video but this is a simple way of changing the color of an object albedo and we can press the back button to go back and see our mesh properties and I can select any other node and we can see its properties over here okay so that's materials on mesh objects that you create inside of the dough if you're wondering if you select Steve and go to his scene and we go to his mesh instance the the mesh that we brought in from a blender this mesh actually has the material in a different slot if I look at its if I you know expands it out it doesn't necessarily have the same material section there is a material section on the outside of the mesh kind of I'm not really sure why there's two spots one for surface and one for material the material appears to be empty but when you export a gltf from blender it gives it a material or a supermini surface with a material on it but I believe you could have multiple surfaces and multiple materials if you want from from blender so here we have under surface one a slot for the material and I could even save it as a material resource and put on other objects but that's where things are for for this okay so I'm gonna close Steve the seam and we're back in our main level next up let's program our ball to roll because if I play my scene of course the ball just skids around now if we actually look at Steve if I go into his scene you can see that he's a box really he's a box with an internal mesh for looks only a sphere and if I select his collision shape we can see the box it's gonna be sliding along the ground so we're actually not gonna make Steve himself roll because that would be rolling a box on a floor and that wouldn't work very well instead we're just going to fake it and we're gonna roll the internal I'll rotate the internal mesh inside of the ball as if the ball itself was ruling so let's go ahead and go back to our level and I can close Steve because we're not actually gonna work inside of Steve I'm gonna go to Steve I'm gonna look at his script this is the code that we finished in the last video so I'm gonna go ahead and be clear this output panel so I can make that gonna make it shorter no I guess I can't I can make this fullscreen now good this is a code from the last video in which we used if statements to detect if we were pressing arrow keys which really called actions on a keyboard and if we pressed the keys that are associated with you I write UI left UI up UI down these are the names of actions then we move our character using this move and slide method or function and every time we press an arrow key on the keyboard it adjusts a variable called velocity that has three values it's a vector three for an x y&z direction and it just works but these if statements only have one result now if I press the right arrow key it'll move my character on the x axis or more specifically change the velocity on the x axis and then move using that velocity on that x axis but we can actually have more than one result if you press the right arrow key or more than one thing happen so I'm gonna press at the end of this line under the right arrow key I'm gonna press ENTER and I'm gonna make the mesh inside this object rotate so how do you actually target something that isn't this object you know if I just said you know rotate on some axis or just rotate and then maybe a number and then close the bracket that would actually just rotate you know the outer kinematic body which we know is a box I don't want to do that I wanna take something that is a child of this node what am I talking about here well inside of Steve if I look at the inside of his scene Steve is a node is the root of his own scene but I want to go from Steve and say hey make my mesh instance wrote in certain directions so how do we do that how do we say the name of this node well what I can do is go back to my level and go back to the script is right here I'm gonna put a dollar sign and then I'm gonna write the name of the node that I want to target and if I have a dollar sign you're gonna see that it lists for me all the children of this node of Steve it has a collision shape and it has him as a mesh instance so I'm gonna select the mesh instance or you can just type it out for yourself and I not type a dot because now we can use methods that are built into mesh instances that were allowed to use so I'm gonna use that rotate one again so I'll type it dot just one rotate underscore Z I believe we'll go ahead and check that if you don't get that prompt you can just type it for yourself sometimes it doesn't quite pick up and you could type rotate it doesn't know it doesn't give you hints so just type it out for yourself rotate underscore Z and put round brackets there Y Z why aren't we rotating on the X well if I go and look at my 3d scene if we were to look from the cameras point of view so this is the camera here this is the way that we're looking this red axis is the way that we move left and right it's the x axis but if we're moving that way we're gonna be spinning this way which is actually on the blue z-axis so we're gonna spin when we move left and right on the z axis that's why I'm using an angle back to the script now that's why I'm using rotate Z if we look at the 3d scene again and re rotate forward and backwards we're moving on the z axis but we're gonna be spinning on the x on the red using that whoo but I have white right now okay so hopefully that makes sense I'm going to go back to Steve's code and we're gonna rotate on the z axis using not degrees if I type in three here you would think it would take a number of degrees no it uses radians and you might not be familiar with radians unless perhaps you've passed around great ten math or so in some countries radians are more tricky and we're not use them as much as we are normally degrees from let's say middle school or so so instead of using a number that we're familiar with we have to use radians but we can be tricky and we can introvert degrees into radians so in these round brackets that we're giving toward the rotate function I'm gonna put a function called Dec - rad and when I put round brackets it's a method or function call and in those round brackets I'm gonna take the number of degrees that I want I'm gonna try eight or so so what I'm doing here is I'm converting degrees eight degrees into radians and then it will give the radians to rotate Z okay on the mesh instance let's go ahead and try this out but I'm gonna copy and paste this line and we press left I'm gonna rotate the same amount but negative and let's do a quick ctrl s to save and I'm gonna play this scene this is our level scene and I press the right arrow key I spin but it's the wrong direction and yes left is going the wrong direction as well so I'm gonna change my numbers and flip them so negative to positive and positive to negative okay let's try that again and it'll be just a guess in check for you to see what number looks good to you I think you might be spinning a little bit too fast based on how much it's moving here so I might try six or seven or six point five or seven point two but what you should do is make a constant a constant will be used or it's better to use instead of a hard programmed or a hard-coded number because then you can change it just in one place so I'm gonna make a constant and recall from the last video I think I actually forgot to mention that a constant is a variable that you don't change during the time that you're running the game so it doesn't change you the programmer sets it like the speed and it's always gonna be that way when you're playing the game no one can access it yeah it's just in the background like a I gotta always the same number so I'm gonna name this wrote speed I'm gonna make it equal to I don't know seven so now instead of giving the number eight here I'm gonna give rut speed and here wrote speed and I think we are good let's go ahead and copy this because we're lazy coders here and when we press up we're gonna be moving on the z axis but we're going to rotate on the x axis of change that and we're gonna leave that the same I'm gonna copy that length again cuz we're lazy coders go down to the down and we rotate with the or move towards us with the down arrow key I'm gonna negative move and negative a rotate negative wrote Spieth let's go and try this out it could be backwards there I'm not sure I press right I'm rotating the right way left is good forward and back our opposite so it's a guess and check scenario here so a positive negative and negative to positive let's go ahead and try that out and we are looking pretty good to me so I'm happy with that now perhaps it is rotating more quickly than it should if you move diagonally by pressing down to the arrow keys but I'm not gonna be that picky for this first intro game okay so that's how you can make things rotate I'll leave this on the screen for a second but we've got one more thing to do we need to look at how to change these actions and change what arrow keys are associated with this action named UI right ui left and up and down so if you want to be able to play with this game and use the WASD Keys this is how up in the project menu we need to go to our project settings and recall that the command or method that we're calling is called is action pressed so we're looking at action names here and I go up to project project settings there are lots of categories in the left hand side but actually we're going to go up to one of the tabs at the top there's lots of stuff here so don't get confused under input map along the top tab these are the names of actions that are built into Godot by default UI select you I left you I up you write down UI cancel and they all are actions that have keys or different triggers associated with them sometimes their keys with a little K icon sometimes there are directional buttons or joysticks on a game controller so you can really create these these names for actions and associate whatever Keys you want with them and multiple keys or multiple different types of inputs with them so I'm gonna look at you I left and it has the left arrow key this little K icon means key associated with it what I need to do is well you won't have this you won't have this a here I'm gonna get rid of that and press the the trashcan there to get rid of that I'm gonna press next to left the plus button now I'm gonna say it make a new key mapped to it so I'm gonna select key it says press a key so I'm gonna press a on my keyboard it's a capital even though I didn't hold shift on my keyboard I'll press ok and now we've got a associated with you I left I've already gone ahead and done all of these so I went to UI right I'll get rid of the D just to show you I went to this + next to i right and I used a key and I pressed the D key on my keyboard and I pressed okay so now I have a for left D for right if I look at up-and-down I've already done these the W key is up and the S key is down so if I press close and I go and play in my game I'll just press the play scene button and I press the duck the w key I go forward the S key I go back the a key and the D key but I can also use the arrow keys if I want so now I'm using the arrow keys now I'm using the a and D keys okay that will I believe be it for this video of course if you like this video for doing something go ahead and click on that like button below this video on YouTube if you want to see more videos like this one in Godot or blender or technology in general click on that subscribe button as well and click on that Bell icon to get notified whenever I upload a new tutorial check out my facebook page at facebook.com slash born CG that's where I communicate with people who subscribe and my viewers the most I post sneak peeks and previews of what I'm working on next but that will be if this video thanks for watching goodbye you
Info
Channel: BornCG
Views: 85,444
Rating: undefined out of 5
Keywords: tutorial, lesson, 3D, beginner, game engine, game, engine, godot, blender, blender 2.8, gltf, roll, rotation, programming, code, coding, gdscript
Id: VWy4ErYd630
Channel Id: undefined
Length: 31min 10sec (1870 seconds)
Published: Tue May 28 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.