Hey guys what is up this is mr. Fujita here and I’m coming at you with a new 2d minecraft tutorial series RPG style I don’t even remember the whole title but yeah let’s get started so in the last episode we created some GUI and before that we did block pickups and before That we did placing in breaking blocks and before that we did a character controller and before that we got started with the whole development of this game and here we are now and I have happened to lose the files for the project unfortunately but this gives us the opportunity to take what we’ve Learned from those previous tutorials and apply it to this version of the game in a much more clean and and I guess efficient fashion so before we get started with this tutorial you’re going to need to do a couple of things first of all you’re going to want to get unity Preferably unity Pro but you don’t need it at all but pro is obviously better yeah you don’t need unity Pro but it’s a good tool to have in general another thing you’re going to need is you’re going to want to go to unity 3d comm learn and then tutorials and check out Everything in here for scripting you at least need beginner intermediate not so much but it’s good to look at all of these these aren’t even the complicated videos these here this sounds like four minutes and this one is a pretty long one excuse the interruption yeah so these this one’s Actually a pretty long one some of them are really short this one’s even a minute and a half approximately the tutorials are in c-sharp but you’ve got here the examples in JavaScript so a lot of this stuff is very easily transferred from one language to another yeah so once you’ve Got all that done you can come back here if you feel confident you can continue on with this anyways so let’s get started the first thing we want to do is we want to create a new Java Script called the world okay this is going to store all the data for a world Generation okay so on reformat is such as public class world extends mana behavior it’s better to hold everything in classes and obviously that’s the way c-sharp is structured so I mean it’s better it’s I’d I’m not exactly sure I don’t really remember cuz I learned this a while ago But there is the tutorial on it and there are various reasons why it’s good to structure in this form so convert I don’t know so now we’re gonna go ahead and type in a function start and function update okay so a pond start we want to create a new game object so far Or let’s say okay you know what let’s actually create a public variable here for the chunks of our chunk so a prefab of a chunk and let’s say chunk equals new game object chunk and that’s actually it cuz it’s got to be empty actually you know what type of Actually we’re not gonna do that right now we’ll add that later when we create the chunk class and I don’t think there will be a chunk class to be honest I’m not sure maybe we won’t need one okay so chunk is a new game object chunk So if we drag this onto our main camera here and we start the game now we’ll see it we’ve got a new game object to your chunk zero zero zero it has absolutely nothing but it’s called a chunk so that’s a good way to start it be okay so Now we need to create a new game object Oh actually we’ll say yeah hmm okay fire okay I’m gonna go like this and we’ll say block and then we’ll use type of so basically we’re gonna create a variable for a block and we’re going to instantiate this all over the chunk so It fills the chunk and that becomes the chunk and then we can start spawning more of those as we move around to create some form of infinite drain so type of sprite renderer type of what do we need here box Collider 2d and then type of you can also have a we’re also Going to need the circle Collider 2d I think that’s all we need for now so for int or not yeah for VAR or I go int ok I got a double check because I don’t remember I haven’t done for loops and ages and they are pretty important when Doing the stuff like spawning chunks so for loops unity loops I don’t know where my window is so small here there we go let’s just maximize it a bit ok yeah ok oh there we go equals zero an eyes less than number of enemies which is variable it doesn’t Exist i plus plus okay so when I is less than 16 or you know what let’s make a let’s do chunk width okay and then we’ll create a variable here chunk width equals int and large chunk height equals int I will make this a private variable To chunk one okay so for VAR i chunk with i plus plus and will actually make this w it’s w is kind of an abbreviation of width so instantiate block vector2 oh we actually need to do one more thing for VAR h int equals zero H sorry it’s Less than chunk height H plus plus or you want to do we want to do – – actually because the height it gets deeper so instantiate block vector to zero I know width height quaternion dot I didn’t I tend to do and we’re actually gonna say um block underscore instance equals Instantiate and then I’m gonna say block underscore instance dot wait what were we gonna do with the blocks again once they’re placed so it places them all yeah so we’re not actually gonna we’re gonna try this out first and we want to throw and destroy block so we want to Destroy the first copy of the block that was placed here yeah that should work okay yeah so that should work so I’m going to test this out here let’s see if we have any errors okay we do have a couple of errors here oh sorry they’re right here what’s wrong with this oh That’s to be an equal sign sorry expecting close bracket found type of there also needs to be a little apostrophe there or comma sorry these little mistakes can throw you off okay so if we hit the pause button and we hit play it’ll at the very first frame we’ve got chunk We have no block let’s remove this destroy block thing okay let’s hit pause pause and play they go now we’ve got one block in the center with everything we told it to have but it’s not instantiating anything oh that’s right I’m an idiot I would trunk width and trunk height is Zero so let’s go here and 16 by 16 oh okay pause play and it’ll take a bit because it’s got to create 64 no even more than that 16 times 16 it’s like 128 isn’t it I think ya know it’s even more than that I don’t know whatever point is it’s creating Along so it’s gonna take a while or maybe it’s just bugged out it’s not supposed to do anything oh it’s the height we can’t change this to – – well we made a mistake there okay unity is gonna crash we’re gonna have to close the window let’s call in the task manager Here unity and task okay so I made a foolish mistake there let’s open up unity again luckily we didn’t have anything in the scene all we need to do is drag our world script back onto here sixteen by sixteen pause play okay there you go it’s got quite a bit Of clones of the block and as we can see all of them are in their own separate places so if we were to actually extend the size of the Box Collider and this 0.5 and this to one and one which will have to change soon then you’ll notice That it creates a perfect 16 by 16 block of blocks actually so this this first now we can delete this first block so let’s bring that line of code back in destroy block and now this should work fine if we hit play and there we are so There’s no original block there’s just a bunch of these clones okay cool so one thing we want to do quickly before this for loop we want to adjust the the values in these components for the regular block so that these spawned blocks are okay as well so far no Blonk ‘don’t get component box box Collider 2d dot size is it I think it’s size let’s check it out here box Collider 2d I always go to the scripting API here and I check out the the variables so yes it is sighs so dot size equals vector 2 1 1 and also block dot getcomponent circle Collider o Collider 2d dot radius radius equals 0.5 oh no one not one point five zero point five and that should automatically scale everything properly so let’s go ahead and hit play here and now if you click on one of them You’ve got one one and zero point five and it’s perfectly square so in that case by selecting all of them we’ll have that perfect grid that we had before okay cool that’s good currently we have absolutely nothing being rendered another thing that you might notice is that the chunk actually Goes above the zero level I don’t know if we want that in this case maybe we do that’s how minecraft was built zero is absolute bedrock let’s yeah let’s build it that way okay yeah let’s build it that way but one thing we want to do is We want to make sure the chunks chunk is centered so let’s go and say chunk dot transform the dot position dot X equals equals math F no chunk height no width with sorry width / 2 chunk don’t transform down position actually we can go ahead And do this math F dot round chunk width so I write 2 and that should work fine there so now it should be because half of 16 is 8 so it’ll just be a regular 8 but if it was something like 15 half of 15 is 7.5 so automatically round to 8 Because we don’t want to use the point 5 for a block game so if we hit play here these will still be all in the same place obviously oh well these are all in the same place starts here ends all the way up there I think it was I don’t know But the chunk now starts oh it starts above 8 okay that’s a problem there we need to start it at below 8 equals negative math after around and now it will start at below it negative 8 there you go okay mm-hmm hmm I don’t think we should do this right Now actually them so let’s let’s actually comment out this first let’s say block underscore instance dot transformed on parents equals chunk and then we can move the chunk after that so now if we look in here this will probably be much cleaner oh yes that’s right Chunk dot transform now if we move in here and we hit play yeah now they’re all a child of the chunk and the chunk can move them around as she wishes okay now we go before after we destroy the block or before that doesn’t matter We’ll go after we can copy this line of code or cut it and paste it and it should work fine no wrong thing there here we go like we’ve got a chunk here kind of halfway through that’s good that’s good okay it’s very good hmm uh-huh okay yeah that’s good so that’s creating The first chunk and now we want to create some more variables here actually we want to create three chunks so after this we’re gonna go instantiate chunk chunk that position don’t transform not actually vector2 from transformed opposition x- chunk width and chunk thought that transformed our Position Don why and then we go quote tyranny and identity okay so now you have two chunks here right next to each other good and now we need to create in third chunk quickly so this one’s plus chunk width chunk dot transform down position dot y quaternion dot identity okay I think we’ve been recording for about a half-hour so this episode will be over fairly soon but now as you see we’ve got three chunks all creating one large kind of group here so what we’re gonna do is we’re gonna create two imaginary points in space okay with three actually one’s Going to be the spawn point and then one will be here and one will be here this one will be a left kind of kind of indicator there’s gonna be a right kind of indicator whoops a bad let’s just select all these chunks again so basically what happens is when the Player passes the left indicator it will spawn on one more chunk and the left indicator will move down here a bit more and the right indicator will move with it that way you can endlessly spawn chunks so I say we can actually add that right now we’ll squeeze that in that’ll Be pretty quick so let’s create two more variables so private the far left in the Kade drawer and I want to actually rename this from block underscore and since the block capital I instance because that’s how I was formatting my variables from the beginning so we’ll go Like that okay that should be fine left indicator equals vector two which is a vector to no open ragged clothes back in and private of our right indicate or vector – okay so on awake actually yeah and then we also need that spawn point one so so after we spawn the very first Chunk as a spawn point becomes chunk dot transform dot position okay so that will make the spawn point at 0 0 0 then then after these 3 are spawned we’ll deal with the left and right indicators so left indicate or equals Oh left indicator equals spawn point minus Vector 2 I’m sorry hold on one moment sorry about that I’m sorry about that okay so equals spawn point vector 2 minus and then we’ll go not sigh yeah we’ll go 16-0 and then right indicate or equals spawn point plus vector 2 16 0 okay and this Should be fine no errors do we have any nope okay so if I stop the game here so basically this position right here is where the original chunk is spawned so this is where the spawn point will be located and then of course the chunk is Spawned in this little area here I would suppose let’s still say for example and then it’s moved halfway through so it’s about here now okay this moves all the way down here as the left indicator and now when you pass this point you continue so let’s see how this will look It’s the leader game object here chunk chunk chunk so let’s select our chunks here let’s see where a left indicator would be a way we can okay yeah there’s no point in the left indicator right now because we have to do the chunk updating So if oh we have to put a variable for player yeah so I we don’t even need to create it here let’s just say our player equals game object don’t find o equals game object on find with tag clear so if player dot transformed on position X is Less than left indicate or dot transform dot position X or left indicator dot X actually because it’s a vector – then something will happen and of course if we’re done transform position dot X greater than right indicator dot X something else will happen okay so in here Right left indicate or plus equals or minus equals chunk width oh and this has got to change from this to chunk width and it’s got to change from this to junk away that way we can freely change the size of our trunk width and the left indicator and right indicator and chunk Spawning will all still work left indicator minus equals chunk width right indicate or minus equals chunk width instantiate chunk let’s see actually let’s instantiate the chunk first so let’s cut this year sand shade chunk left it left no yeah left indicator dot left indicator – Vector to 16 or chunk with let’s try 6 no chunk width + chunk width divided by 2 and then 0 of course and then we can go quaternion identity then this moves down ok let’s see how this looks here Oh – cannot be used with what I do wrong Left indicator dot X dot X there we go ok so let’s create a player here River great empty zero zero zero and then we’ll create a temporary script here great nod whatever and they’ll basically just quickly say just be quick if input put get key down key code dot a Game object 3 x times delta time we’re not gonna keep the script so don’t bother copying this don’t bother copying this don’t X I keep forgetting that ok so now if you play here no reference exception at 34 hmm that’s right we don’t have a variable for the player Because I forgot to tag the player this is our player tag him his player now if we play you don’t get any more errors do we wait hold on yet no errors so now the player should move just why doesn’t he move when I press a can he not move What’s going on did I do this properly oh it key my bad sorry I understand up doing anything move your freaking player there you go now he’s moving oh he’s not moving I’m such an idiot okay you know what now he’s moving okay where is our our thing is so let’s Select these chunks so as soon as we pass I think here or something it will spawn another chunk so let’s look over here when it spawns the other chunk there you go it’s spawned another chunk so now let’s make sure that these chunks this one whoa okay so we have our perfectly tiled Chunks are these perfectly tiles and right there the other one starts right there yep they are perfectly tiled so that is actually really good I had a bit of doubt in that one right there so now we can just kind of copy the same line of code here except now we’ll switch Around the operator so this one will be plus equals this one will be plus equals this one will be plus oh and this will be right indicate or not left indicator okay and I’m going to modify this so that he can move both left and right so if actually I’ll just copy this Okay now let’s take a look at this my bad now let’s take a look at this okay so play we’ve got a three chunks let’s move all the way to the left or right first let’s see if the new chunk spawns in then we’ll move all the way to the Left so will this show can you get anything that will show no okay because they’re not textured at all so let’s check out our game object here oops move all the way to about 16 here I go create a new chunk ooh this one is a bit Awkward hmm so we do need to actually modify this trunk with – trunk with / – this should work let’s continue down to about 16 here BAM 16 new chunk is spawned Bam Bam Bam and the new chunk tell us perfectly yes okay now let’s move our player on down To the other end and see if the other chunk we create is fine as well oh oh that is a problem we don’t actually want our left to move when our right is passed because then the chunk that’s already there will be overlapped with another chunk so we don’t actually want That we’ll have a different way of modifying things so actually just remove the right part from the left side and remove the left part from the right side and we should be fine now so I don’t really want to test again let’s just make our game object go freaking Lightening speed let’s say about 15 so 5 times what it currently does and let’s test this out and see how this works so it’s just going to create legions of chunks here my frame rate is staying steady because of vsync it’s only here it should be rocketing right now no Extra draw calls are being called nothing is really changing this is a naturally just wobbling around it’s not doing much here and there you have it we have tons of chunks all in perfect line so you might be wondering if the player moves all the way down here won’t his Game start lagging when we actually have stuff being rendered here and yes it will that’s why you can great a system so that when the player is when when the camera can’t see the block the block is invisible and that will help us run the game better so thank you for watching of Course please subscribe to Boris’s channel please subscribe to my channel as well mr. underscore Vegeta capital m capital F follow me on twitter m under scoreless on for updates and also you can ask me questions about coding and stuff there anyways the next episode we will do some texturing probably will get The we’ll get the design or at least we’ll get a color there so you can see where the chunks are and then we can throw in a player to walk around and stuff like that so I hope you guys enjoyed this episode this time we’re starting with the priorities which is Obviously infinite worlds such as you guys probably came here for I don’t know I might be wrong but Oh Video Information
This video, titled ‘2D Minecraft RPG – A Fresh Start (World Generation Basics)’, was uploaded by BorisMediaProds on 2014-07-27 19:25:33. It has garnered 2387 views and 18 likes. The duration of the video is 00:37:32 or 2252 seconds.
Please excuse the low bitrate – Thank you.
This episode we uncover that Mr_Fudgito’s previous files have been lost, so we have to start from scratch (Which gives us the opportunity to improve and simplify what we made before)
For help or questions about this, or any other type of code (Unity), please tweet out Mr_Fudgito @m_lasan
Thanks for watching, outro music made by Deadhor5e, check him out on soundcloud here