Unity 3d: Making a Board Game! - Episode 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this week's episodes were brought to you by the generous support of Yuko Finn hey folks Quilly team here and welcome to a brand new tutorial for unity3d today we are gonna be working on a board game now I want to come in it and explain why I'm doing this tutorial I'm still working at this time I intend to do more work on the mostly civilized hex engine and in particular I've been trying to work on a talk for like the last couple weeks maybe three weeks now about artificial intelligence about AI and I haven't been able to really like find the right way to approach it in a way that's interesting informative and accessible and so I thought you know what I'm gonna go through my backlog of emails of people who have requested various tutorials I'm gonna pick something out that should be relatively easy to do programming juices again you know get something online get back in the mode of it and then we'll figure out this AI thing later and I ran into this email from David who says hi my name is David I have a programming question I've just started programming and I'm also a big fan of board games I thought about making I thought I could make a basic 3d board game in unity the game I'm trying to do is the Royal game of ur after hours of trying I can't figure out how to do it I'd love if you could make tutorial on making this game with its basic rules the Royal game of ur is one of the oldest possibly the oldest true board game ever ever ever ever ever the rules fort were recently translated by someone at the British Museum apparently and it looks like it's a very early form of a backgammon kind of game so what's gonna be amazing about this is this gonna be a great tutorial for some basic unity stuff this is one of the things you don't need a lot of advanced knowledge to follow along this tutorial we are gonna make this board game it's gonna be excellent but not only that after we're done making the actual board game will sort of end that part of the tutorial and then move into writing an AI that can play the board game against a human player and it's gonna be the perfect way to go into artificial intelligence and talking about that kind of stuff I'm really excited so thank you very much David for that suggestion which was back in September but I've kept it Bank because it was a good one and we're gonna have a great time with it so again first part of the story is gonna be available it's gonna be really easy to follow learning the unity basics it's going to be a good time and we're gonna make this board game it's not very dissimilar to something like backgammon or even like if you've ever played like this is the game sorry when you were a kid it's very simple like that it's just basically roll the dice sort of move your pieces around if you land on someone you bought them back to the start you want to get your pieces off the board so let's pop into unity over here I have a blank project set up I am running unity 20 17.1 but this will probably work in basically any version of unity you've got it's really not gonna use much in the way of advanced functions or weirdness like that it should be very very very straightforward it's basically an empty project I did go ahead and create two textures they're lovely we've got a blank tile and we've got a pile that says roll again now if you are more artsy than I am one of the things you could do is grab this image here which is you know one of these old boards bring it into Photoshop and like maybe you can you can correct the angles and then draw over all the the pieces so you get a nice crisp clear version of these exact symbols for your for your board game or something like that but we are gonna work with just the graphic skills that I have available to myself not very much okay so we're gonna leave those aside for now anyway so in our unity project here we're gonna start by making a cube because we're gonna have each tile is going to be a cube now there's no reason you couldn't do this as a 2-d game I mean basically when you're working in 2d you're just uh your camera's just locked this way or something like that and you're gonna be working with like 2d sprites instead of cube tiles but the logic is a hundred percent the same still um I think it'll be fun to work in in sort of 3d to get this going so that's what we're gonna do so go to the game object menu go to 3d object and let's start by making cube this will be the base pile the base Square that you can land on but so you know again it's a square we only need the top bit but we'll give it a little bit of depth this way it's gonna look okay you can of course Mouse in and out I like to work in isometric mode over here by default unity does set you into perspective mode in perspective mode I don't tend to like to work with it because when you're in perspective mode and you drag your your right mouse button around it just rotates the camera whereas when you're an isometric mode whatever you've you you're focused on you rotate your orbit your camera around it and I personally just find that way way hand here for myself alright so we got that in our basic scene we do have the main camera and we've got a light in there we don't really need the game the game tab right now so what I'm gonna do is I'm just gonna go and hide it like that I mean you you probably have a different layout to do your particular unity thing but you know as long as you've got your hierarchy your project your inspector and your scene view over here you're good later on we will need the console which is why I have it nice and centered over there so a couple of things first thing is this cube is the graphic is the visual for the tile that our piece is going to go on right each one of these again each one of these is gonna be one of these little squares here we're just gonna screw everything together so it looks like one cohesive board you could of course model this in another program you could do a few different things to get the look but I'm gonna do this because it's very simple to work with and get started you can always like change things up later you can like lay everything out with these cubes and then decide to make a fancy model leave these cubes here just make them invisible so all the logic we're gonna develop you could totally do and just use the cubes as like place markers for this is the place where you know you put your pieces and whatnot but you can actually make them invisible um now this cube is the graphic and one of the things if you haven't already learned this in unity it's gonna be a lesson inevitably you will learn never make your graphic object your visual object just the sort of base object that's in your hierarchy always have it nested in something else it'll save you a ton of trouble and let's talk about why first of all let's take this cube let's go ahead and and Center it so I'm just gonna go into the transform here I'm gonna reset it to zero zero zero just double click on it to center it over here okay um then what I'm gonna do is I'm gonna create an empty game object so this cube this I'm gonna call cube - visual and this empty game object that we've just created I'm gonna call this something like like tile like it's the spot where you can put your gun I'm gonna call it the title over here and then I'm gonna take the cube and put it inside the tile now assuming you had everything centered and everything like that the visual inside of the tile should say its position a zero zero zero if it's not take your cube visual set it to zero zero zero here and what you've got is the tile spot like below the the 3d widget here your transformation widget shows you the raw coordinate the zero zero zero of both your tile empty game object as well as your cube visuals and they're pretty much there if I take my tile now and let's say I move it I'll just move it up so my empty game object is now two Y of one my cube visual still has a value of zero inside of its parent over here and it makes it a lot easier by doing something like this what it means is we can put all kinds of game logic on this tile game object right we could add our scripts and everything on here if we decide to replace our visuals we can totally do that what if we decide you know what towels are stupid I'm gonna delete the key or sorry cubes are stupid I'm gonna delete this cube and instead what I'm gonna do is I'm gonna create a 3d sphere inside of a tile that's great your tile object is still there with all the attached you know logic scripts that you've added all the components you've added your tile but we've changed the visual or maybe you've made yourself a 3d object in in blender or 3d studio max or something like that and you want to swap out the visual it's awesome the other thing I'm just gonna go ahead and undo a few times here to get my cube back the other thing that's really nice is this again this marker here when you've got the tile selected this is at the 0 0 plane right like if we look the line this line over here is y equals 0 that's the 0 height well the top of the cube is actually like 0.5 units because the whole cube is one unit tall so it's sticking upwards by half a unit that might be kind of awkward to work with wouldn't it be better if we took the cube and moved it down and I mean move it and moving it down sort of manually like this or by dragging the Y here is kind of awkward but if you like get it close you're like oh yeah what if we moved it down to negative 0.5 now what's great about this is the top of the cube is aligned with y equals 0 that feels like a great way to work so anything where you set it to y equals 0 should sit on top of the cube but if we click on the actual tile game object you can see it's transform is still aligned at the zero zero zero spot really much nicer to work with so that's the advantage you can swap out the visuals and it's a little easier line things okay I'm gonna take it ctrl s to save here and I'm just gonna go ahead and I for whatever reason I just like to name my scene this you totally don't have to copy this idea this is just my particular little thing to make it easy to to see anyway so we've got a cube nicely set here this is going to be a tile now we are going to add a visual component to this tile here we're going to texture it or give it a material so these words are a little bit interchangeable what the cube represents the cube itself has several different components on here it has a mesh filter it has a box Collider which we probably won't need but we'll leave it there the box Collider is just for the physic system we're gonna ignore it for now so again it has the mesh filter it has the mesh renderer and the mesh renderer has a material slot over here which you can see info there and we can increase this and get some more information about it the mesh filter itself contains the information about the triangles and the mesh the vertices of triangles that make up your 3d object if you go to your scene over here and you switch to wireframe view you can actually see the actual these little blue lines there might be a little set hard to see on YouTube that describe the triangle each face of this cube is made up of two triangles because everything in 3d is made up of triangles that's what gets sent to your 3d processor I mean quads are sort of a thing but not really things let's ignore that for now so yeah so that's what the mesh has but the only way that your graphic card knows how to actually draw the mesh on screen how to render the mesh on screen is the information you get the mesh renderer which tells you things like hey do we use lighting or whatever and what shader to use the shader is the real instructions to the graphic card that tell it how to draw something on the screen now actual shader work is way more advanced than this tutorial but one of the things a shader can take is a material slot now a material is really just a unity thing - that is a handy-dandy interface to the shader and one of the things the material can take is a texture it can take an image to be used in the rendering so let's go we're going to create a new folder I'm gonna call this materials and I'm gonna make a material in here so I'm gonna create material and I'm gonna call this material now this materials gonna use the standard shader I'm gonna call this like pile okay so we have a material called pile and it has this albedo slot which I know is not terribly informative it has to do with the physical based renderer that is present in unity as of what unity 5 or something like that but this is where you put in your normal image texture to like have something drawn onto your cube so if I take this tile texture so this is my this is just a square graphic I just drew it in two seconds in Photoshop it's just a black border with the white in the middle and that's all there is to it if I take this tile and I've got okay I've got the material the tile material selected and then with the tile material selected I click and drag the tile texture into this albedo slot over there all of a sudden this material has my texture applied to it now this is the preview over here you can change what object is used as the preview for example oops a cube over here which is kind of informative kids what we're going to do now if you don't want to click and drag you can also click on little dotted circle here the target this will bring up a list of all the possible textures in your game and then you can pick the texture that you want from there okay so now we have a material defined let's apply that material to our cube visual so again went the cube visual selected in the mesh renderer area there's this materials section over here and it has the default material attached to it we can drag the tile material into that or again you can hit the dotted circle over here for the target and then we're going to target the tile material and close that so my tile material has now been applied to our cube now what we're gonna need is running a series of these because we are gonna want these cubes I'm gonna take this directional light and move it like a million miles away nice thing about the material light or the directional light it doesn't care where it is in the sea it just does uniform lighting from one direction so we can put a million miles away so that it's you know not in our way over here and annoying us if you go back to the the image from the the British Museum entry on Wikipedia here we can see that we need I think it's twenty titles right because this is twelve thirteen fourteen and another six over here is twenty so we're gonna want a group of those and what we're gonna want to do is basically copy this tile so you can do it a few different ways one of the easiest things you can right click and duplicate you can also do ctrl D on PC or command D on the Mac will create a duplicate of a tile just do this and that's cool but what if we decide we've made a mistake where we need your change what if we're not happy with one of these tiles and we're like you know what because of reasons we need this tile to be bigger we need to take this tile and take its visual and we need to scrape scale it up um by oops this much see it only changes the first one you got to change all the others so what we're gonna do is rather than make a duplicate like this I'm gonna get rid of my extra copies here I'm gonna take this tile and make it into a prefab I'm gonna make a new folder for this keep everything nicely organized I'm going to call it prefabs it's a prefabricated object we take this tile we drag it into prefabs one thing that is interesting this tile text is now blue and that tells you that it's linked to a prefab and what's great about this is that we can take this prefab oops there we go I dragged it in the wrong place there we go we can take this prefab we can drop it back into our scene and these things are linked if I decide to go and make a change to one of these let's say I take it make a change here again I set the size bigger it will only affect the one I'm working on at first and the reason for that is I'm making changes to this instance and you can see that it's in dark font over here but if I hit apply it'll apply that changes to the prefab and every other thing that's based on that prefab will then get updated to match which is really handy so I'm gonna undo this because obviously I don't actually want these cubes bigger like that apparently undo does not affect the prefab okay that's okay I'm just gonna reset it down to one I'm gonna apply the changes there so we're back to a normal cube now I can still go and just duplicate from here you know using ctrl D the copies will still be linked to the prefab so we're gonna be okay so we're gonna need 20 of these in all let's get them out one at a time here let's figure out our layout now we're gonna want to lay these out just like the board on the website now doing this sort of by dragging is a little bit awkward the nice thing because we're using cubes of size one our offsets will always be one like basically I'm gonna want the next one here and you can see from the position here it's like oh that will be negative one is correct that can still be a little awkward to do if I go and duplicate again one of the things you can do if you hold ctrl like I'm holding ctrl right now you sell it snaps really nice so we're gonna do that duplicate again I'm holding ctrl ctrl D start the drag then just holding ctrl it locks it in so I'm going to do the same thing again and again and we need two of these and then duplicate we need one there we need another one there then that goes down there duplicate over there and then we need to do the other side which is you you and it finally over here da da da and dump I have a nice collection of tiles over here they're not necessarily named or ordered in any particular way but we're gonna make an adjustment to that well I guess right about now so the let's explain how this game works basically each player has six pieces and on each player's turn you just take turns you will roll in there in the game you roll four pyramidal dice basically our tetrahedron dice but so they have four points two of the points have a notch and two the poor are painted in in some way and two of the other points don't it's effectively the same as flipping a coin you can think of it as flipping four coins and the number of heads you get is how many pieces you can move forward sometimes you'll get all tails and you'll get 0 sometimes you'll get all heads you can move for sometimes you'll get one two or three who is the most common of the options at about three I think it's three over eight is your chance of getting a two so it's slightly more common than the other possible outcomes so you flip your four coins or roll your your tetrahedrons or whatever you want to do to generate randomness and then you can take one of your pieces and move it forward that many your pieces let's get let's get a dummy piece here I'm going to create tell you what I'm gonna create an empty this is going to be player 1 - piece just cuz whatever inside this empty I'm gonna go and create a let's make it a sphere and let's go and get this piece let me Center it up first double click here to reset my camera view and just pull it off to the side I think what I want to do is I want to take this sphere I want to shrink it a little bit in the X so let's say 0.75 and in the 0.75 so it's a little slimmer this way a little smaller you see then then the square and in the Y direction I want to squish it down quite a bit to make it almost like a little just a little token there we go something like that there you know Pellatt little pod and that will be our playing piece there I mean obviously it should probably have a flat bottom so it doesn't wobble or some of these boards were dug in a little bit so that the the stones would sit properly in there I guess I could call it that player one stone looks like a like it could also be a go stone although the go stones are again they're flattened at the bottom over there so we got a piece there tell you what I'm gonna go ahead and make this a prefab shrink it down make sure when you're dragging these around that you don't grab the sphere like you don't wanna grab the visuals and drag it around you want to grab the main a game object and drag that around so let's say I went and moved it over here now one of the things to note is that this piece is penetrating into the board and that's because our game object is set at a Y of zero and our sphere is also set of the Y of 0 which means the center of the spheres in the middle so again what I'm going to do is grab at this point now I'm grabbing the sphere visual I'm gonna pull it upwards to something like that so it's just resting on the surface good and then I'm gonna apply the changes to the prefab so again the player one stone is at zero but visually it looks like it's sitting properly that's the advantage it's one of the many advantages to nesting everything inside of a game object like this is you can have all of your various pieces all sitting at a Y of 0 but look right so the way it works is you have a bunch of these stones off to the side you you roll your dice then you take one of your stones and starting from this tile here or if you're the other player this tile here you so you would go oh I could quickly drag it there oops I'll grab you there we go so let's say I rolled three I would go one two three and then my opponent would then have a turn and then in my current I would roll again let's say I get one I've got two options now I can either take this guy and move it up by one or I can take one of my other pieces from the side and move it here as a one for example when I get to here then I move into the middle move up this way get all the way to the end over here make a little corner this way and then there and if I can move off the board then that piece has been scored you win when all six of your pieces have been scored and that's it that's the game there's a couple of extra things there's some tiles that you can land on that allow you to rolling in and also are treated as safe spaces and if you happen to land on your opponent's tile let's go let me gonna make a duplicate of this I'm gonna call this player two stone and I'm gonna make a material here let me let's make two materials one is going to be player one - stone material and then we're gonna have material player two - stone material we can have we're not gonna apply an actual texture I'll just change the albedo so we'll make the stones let's let's go with yeah let's go with quite dark and just because my table is white I'm gonna make the player one stone color just a light gray like this it should still be fairly differ unshakeable we're gonna call this the player oh we got a prefab over here so the player to stone I'm going to take the sphere I'm going to set your material to the player to stone material like that I'm gonna apply the changes so that's player two and then the player one stone you get rid of the extra one this one over here we're gonna expand you click on the sphere go to the material and we're gonna sign your material to the player one stone material so there you go so it's oh it's a light gray I think we can clearly tell the difference between these two stones over here we're gonna apply the changes make sure that's all applied and as a bonus the player one stone will be there you go a little bit more visible on top of this what I should probably do is change my little tile color over here my beautifully drawn tile to a different color maybe maybe I'll do that now let me give it like a light bluish kind of tint maybe a paint bucket there save that go here sure something like that I don't know it's it's fine let me make the player one stone color actual back to vibrant white okay just a little off white there we go I think that that pops well enough okay I'm pleased with that anyway so that's it so this player one you go like this and around that's player two you would start over here and around and if you land on someone else's stone you bought them off the board so let's say I am player one and I have a stone here and then player two and I said it's Y back to zero here player q has a stone here and it's player two's turn and player two rolls at two he can go one two and what happens to my stone is it gets bumped off the board and it has to restart the entire trip likewise you cannot have two stones in the same tile if I am here and I roll it to I'm not gonna be allowed to go one two and have two stones in the same tile that is not legal I would be forced to start a new stone over here or advance this guy two steps very very very very very simple rules so there we go I'm gonna take the player stones off the board over here what we're gonna do is I'm gonna go and name these Kyle's to be a little bit clearer so I'm going to name the tiles over here player 1 start - 1 2 3 4 I think that's going to be a relatively reasonable naming convention player 1 - start one and then hit enter to lock that in and this one here is player 1 start - 2 & 3 & 4 now this over here is going to be player to start 1 2 3 & 4 and what we might want to do at this point is reorder our items in the hierarchy just to be a little bit more orderly and and you know sensible so let's take the player to start one and put it right over here there we go so we have the player start tiles sort of grouped up and in the correct order that looks ok be sure not to drop it on one of the other tiles make sure to drop it in between the two tiles or you're gonna change the nesting and do silly things we'll call this something like shared one middle middle one yeah I like that middle one two three four five six seven and eight I don't know this is not particularly exciting but I accidentally copied but doing this sort of stuff will dramatically help you keep your project organized over here and then this is going to be player player one - end 1 and n 2 and then over here its player 2 and 1 and n 2 and again I'm just going to drag the player 2 bits to be in the same the correct order for their movement over there control asked to do a little save over here we've got you coming along very well last thing I mean you in this video because I don't like having a scene hierarchy with a bunch of things in there a great thing you can do to keep things organized is we can go and create a new empty and we're gonna call this the board it's the whole game board now I'm gonna take the transform over here let's make sure to reset it to zero zero zero this is gonna be very important just reset it all to zero zero zero so just setting the middle of the thing then I'm gonna go and select all of our tiles and I'm just gonna put it inside of the board object the great thing about this is it means I can print the board so that our hierarchy is not cluttered and if for some reason we have to move the entire board I can take the entire board and move it around and again locally even if I end up sending the board upwards everything inside still has that local Y of zero which keeps everything nice and clean so I'm just gonna go ahead and recenter the board again at zero great little setup over here very pleased with this okay so I mean we haven't done any real programming yet but we've set up the core of where our environment will be we've got our various materials and prefabs other than making the dice like we've got all the objects than we need we were gonna leave the the dice making - a little bit later because we're gonna talk about a few different techniques so that we might want to use to do that it's not I'll probably be in the next episode in fact I think just for visual appeal what I'm gonna go ahead and do is I'm gonna create a new three object I'm gonna create a plane and I'm gonna set this plane so if I were to set it to zero right it would be level with the top of our board let's set it at a Y of -1 and then we're gonna scale it up to like I don't know 100 you don't have to scale it up into Y you can it makes no difference whatsoever but now we have a nice like nice area for this to sit on we get little shadow effects and stuff you know what actually kind of want to make it smaller again I kind of liked it when it was on a little bit of a surface like this once you find that kind of appealing also I just realized that our middle row oh that's interesting our middle row here is at a Zed of 1 which I don't particularly like I would much prefer it if it were centered on the middle now what I can do is grab the board and give it a little - one nudge over here to get everything centered but I'm actually not super keen on the middle board having that minus one so what I'm going to do is I'm going to wrap all of the middle tiles over here and I mean and give them a Zed of zero then I'm gonna grab all of the player two pieces the player two like this I'm gonna give them the Z of minus one so they're on the other side and all the player one pieces I'm gonna give them the plus one over here which I think will put them closer to the camera well either way well we'll figure that out but there we go our board is once again reset here the actual board object is zero zero zero and it's nicely centered on our midpoint which looks great so I think the plane what do I want to do I think I want to make it a little longer this way I mean we can actually even make like an actual table for it to sit on this thing could have a cool sort of wooden inlay pattern and things like that you know wouldn't it look kind of cool especially if we go ahead and and move into the perspective mode I know something that will figure something out but I think this is a good start so next episode we'll figure out the dice mechanic to make them roll different values which is gonna be very very surprisingly trixie because there's a bunch of gotchas that you've you've got to be aware of and then we'll actually get the pieces to move around the board will implement to human players and then the second part alright the second chapter not the second episode but second chapter of this tutorial we'll be creating an AI opponent for us to play against thanks for watching folks and I'll see you guys next time thank you to all the October patrons who make these videos possible including these Mic Check supporters Yoko Finn Erik Sumner Adam Kenan Davey Danny Welch Tiburon mighty mix Pavel's Danoff Michael McClintock Aaron Tyson roars Col gurko dries TN s EE Jasper Bisgaard Julianna the foam Mary's filled votes PT Cervantes even Steger Thomas Overson Jason Janna T Stephen Bannerman Easter egg productions and Emile Blakely me no Milner as well as everyone who likes favorites and subscribes to these videos thank you very very much
Info
Channel: quill18creates
Views: 110,776
Rating: undefined out of 5
Keywords: Unity (game Engine), Game Engine (Software Genre), programming, tutorial, first, person, shooter, first person shooter, fps, howto, how to, beginner, guide, unity, unity 3d, unity 4, physics, blender, 2d, 3d, quill18, quill, multiplayer, board game, boardgame, ai, artificial intelligence
Id: LHQ4ynQhPLY
Channel Id: undefined
Length: 31min 26sec (1886 seconds)
Published: Wed Nov 01 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.