Blender Game Engine Basics Tutorial #4 : Game Screens & Collision #b3d #gamelogic

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome art form of a TV series in the blender game engine in this video I'll show you how to switch screens in your game in other words if you want a game menu or a windscreen or a loo screen or even more levels in your game you'll need a way to switch screens in other words change everything that's on the screen all at once let's go ahead and dive in of course the first thing we have to do here is change our render engine to the blender game engine to get access to everything that that entails and I got to go ahead and divide this 3d viewport into two by grabbing this little triangle area up here and dragging it straight down and making this bottom window into a logic editor window so we have access to and I'll press n to hide this side properties catalán kind of scroll to zoom that we have access to our sensors our controllers and our actuators now when you're making new scenes in your game you're actually or screens in your game rather you're making new scenes and I haven't talked about this yet in any of my other blender videos but up here in the information bar we have scenes which means you can make different scenes for let's say a movie all in the same blender file and you can copy and reference things from one scene together if you need the same props or same characters between different scenes and that's all good and great but we'll do right now is make this scene right now into our game scene so I'm going to name this scene game just by clicking in this little box and typing and I want to make a new scene now so what I'm doing in this video is making a bad guy or something that you don't want to touch then we'll make this cube into our character and if you run into the thing that you don't want to hit and then we'll go to the ulugh screen so I'm gonna make a new screen now by making a new scene pressing this little plus button and when we press this plus button it brings up a new scene menu and you can click new and it'll make a new blank scene with nothing in it you can copy the settings from your current scene so if you've changed things like the gravity in your scene or anything else it'll copy that you can link objects or link objects that I'm not going to talk about what those are or you can make a full copy which is which is great too if you want to copy most things over and then delete things later I'm going to make a new scene so click new and it makes a whole new blank everything you don't even get a cube or a lamp per camera so the first thing I'll do is I'm going to name this scene this is going to be called screen lose and did I call it one scene I called scene I'm going to name the first one screen because this is a game and I'm going to switch back over to the loo screen and I'm going to add a few things the first thing we need to add is a camera because when you switch screens where does blender know to go to what's your what's your view going to be well it's going to be through your camera and let it will automatically do that so I'll press shift a and it'll bring up the add menu and I'll add a new camera and when blender adds new cameras unfortunately the rotation is sort of at this diagonal I don't want that so I'll press alt R on my keyboard and that will clear the rotation so it's pointing straight down and that's okay because we're going to lay out our screen on this mesh ground I'm going to grab my camera and drag straight up on the z-axis to move it up and so now if I press zero on my numpad or go to view and camera I can see the ground and if I want to move it up or down I can just make a second window in fact I'll do that I'll drag that across and in this window I'll press 0 or go to view and then perspective or just click camera again that will toggle between your different views and I can move it up or down what I might do is I might change this camera to be orthographic that means make it pretty much a 2 dimensional 2d camera with no sense of depth to make like a flat text only or text and graphic screen to do that with the camera selected I can go to the camera tab in the properties window and I'm gonna change it from perspective which means you can have like a different like a wide-angle or a fish angle lens or have things look farther away to an orthographic lens as you can see it kind of changes and it gives me an idea of where it's covering on the ground grid so I can really tell and if I want to make it be bigger I can change the orthographic scale okay so it looks like it's wider as you can see as I'm dragging that value it's making it wider so I can fit more things in the screen or make things different scale for my screen so what I'll do here is I'm going to start adding things out things over here doesn't matter put actually what I'll do is maybe combine these two windows together so I'll drag this little triangle area into that one and I'll press shift a or go to the add menu I'm going to add a text object because this is going to be the lose screen so text so shift a or ad and text and the way you edit text is this is not a mesh actually it's actually a special text object and the text just like getting a mesh with its selected you press tab on your keyboard and tab toggles between edit mode and object mode and you can also do that down here at the header of your 3d viewport so object mode and edit mode with a text object when you go into edit mode you get this cursor it's just like a text cursor from Microsoft Word or anything on your computer where you can edit text you can press delete and it'll delete letters and you can write things wanting to write you lose exclamation mark once I'm done typing I press tab or use this menu to go back to object mode and then I can position the text as I see fit if it's too small or too big of course you can select it and press S on your keyboard to scale it but I think it's an okay size for me maybe I'll put it right in the middle approximately and if you want to add color to a text object unfortunately and I'm not sure why the game engine when you press P to play and right now if I press P it won't work because this is not our home screen you can only press P unfortunately when you're on your first scene that you made so we're to work if I go to screen game and press P but if I switch over to screen lose and press P for some reason it doesn't want me to get into that scene right away so P doesn't work text objects cannot have materials and I'm not sure why they just don't show up you can add a material to it if we go a little to real time the properties window and press new and then go to diffuse which is of course the color of objects that light reflects and we make it let's say a red color it's not going to work and so the solution here is we can convert this text object to a mesh if we don't care if it doesn't ever change again in other words if this text is not dynamic if it's not like a counter on the screen or lies in the screen that's going to be a number that's changing we can make animation to do that with the text selected you're going to press alt C c is for convert so all to see and I want to select mesh from curve meta surf text Tech map is if it means mesh from text click that I press tab now you'll see I get access to my vertices and edges and faces but now this material will show up at just a little tip here for text and lots of other objects shading should turn off any specular make it not shiny and I would turn up the emits value to 1 so I'm going to click under shading under the material tab and turn up to 1 that'll make it kind of that solid color um yeah that's going to be it or I might even click shade list to get the real close will be even better advice so I can leave him it at zero but just click on shadeless and that'll make it that color of text under air the font tab if I were to rewind a little bit before I converted this to a mesh there would be a font tab where I can change the text I can change the thought the worst choose Comic Sans or something like that but let's continue I have text I have a scene for my Liu screen let's go back to our game and let's make a really simple and quick game so I'm gonna drag my cube straight up in fact what I'll do is I'm going to move my camera so I'm gonna press this little + and I'm going to select and I think it's under view lock camera to view now what this does is it lets you orbit through within from within this camera view if I sure - or it right now it just breaks air with a camera it doesn't let me orbit to change the position of the camera the cameras right there so it's kind of locked there but if I lock my camera to my view with this the N key on your keyboard with the properties pedal and then I go to my camera view like an orbit so I can change the view that way I'd like a really really simple game here I'm going to make its what my character moves forward on the y-axis and so I'm gonna hit a bad guy over here and the bad guys not going to be moving at all so I've got my ass up what I'll do is I'm going to add a ground object so I'll go to the add menu or press shift a on my keyboard I and a mesh and a plane and the plane is way too small so I'll tap s to scale up and pull the nose out and then I'll click when I'm happy so now I've got a ground my character of course as both meshes are in my scene right now my character is a physics object since I'm using blender game if I go over the physics tab you'll see it's a static object with things will not fall it will not be interactive really won't fall down to the ground with gravity so I'm gonna change this to the physics type we've talked about rigidbody a few times we talk about dynamic well in the last video if you have not seen that I would highly recommend it we talked about how to make a first person shooter controls eye movement for your game where you can control the where your camera looks and where how your character points with the mouse movement on your screen just like a first-person shooter I didn't change my my physics type of this character object to a character we talked about that in the last video so if you didn't see that video at check I check it out let's go ahead and add some logic let's make some controls so with my character selected with physics type character I'm going to add a sensor and actually there and connect them so the sensor is going to be a keyboard sensor and I'm going to add an actuator for motion so I've got those two things I'm going to select what key I want to use to make my character move forward so I'll click on this key button and I'll press the up arrow on my keyboard I want the up arrow to make him go forward or in that direction basically which will be from my camera's view to the right but that's okay in fact maybe I'll just use right that makes more sense for my camera view and a simple motion well that's not what I want if you watching this video you'll know that if you have a physics type of object either dynamic or a rigid body you get more options when you use this simple motion option if I switch this over to dynamic you'll see there's a lot more options here but with character motion and this is a good thing you have less but I'm not going to use some emotion I'm going to use character motion which is an option that kind of corresponds with the physics type although not necessarily so with character motion you'll notice that you get jump again we talked about in the last video I made a character jump but I want this to move the character or the W or right arrow key rather to move the character to the right which is the positive I'll switch my keys mode to local that'll show me that the character actually knows that that direction the Y positive axis is the direction that we want to go so location Y and I'm going to use 0.5 positive because that's the direction the arrow points in and let's go ahead and connect them this is the local access by the way this needs to be dark the L there I'm going to go ahead and connect these two logic bricks and so now if I press P and press the right arrow my character moves so how do we trigger moving from the game screen to the lose screen we'll need a bad guy and then we'll do a collision detection so I'm going to press shift a and I'm going to add a monkey head the monkey will be the bad guy in the scene so v a monkey head I'm going to press 1 and 5 to go to my front orthographic view or I can go view purse ortho and then view front or any side that you want in fact I'm gonna go to my side view with the three key on my numpad and I'm going to grab the monkey head and just put it over to the side and be I'll rotate it so it's sitting on the ground rotate of course is the R key on your keyboard I'll switch back to my global view or my global gizmo so I can see the arrows in their global direction so I can move the monkey straight down and you'll make it a little bigger with the S key to scale there we go I've been a big monkey head let's give it a material I'm going to give it a new material that's going to be read it's gonna be a bad read evil monkey head now this is gonna come in and play a little bit later I'm gonna make the material have a name because there's two ways we can make collision detection happen in the blender game engine with my character I can detect if my player using a logic brick that we haven't talked about yet is going to be hitting a object with a certain material or if the player actually comes into contact with a certain material and in this case if we make a bunch of red monkey heads they're all bad guys well we can detect for that material so I'm gonna name this material right here under the materials tab on the monkey I'm going to call this red bad all red bad duh there we go and so with that knowledge with red bad with a capital B I'm going to go over here to my character and I'm going to just collapse these two bricks without naming them properly and the sensor to make collision detection work is under add sensor of course it is called collision go figure and collision has a couple of ways of working so I'll click on collision it'll add that brick it is a couple of ways of working it can detect a material I just spoke about or it can detect a property and we'll talk about both of these things but the way you toggle between these two modes between detecting a material or a property which again we'll get to is this button right here by default it's property but for now I'll work with material so I'm going to toggle this over to material mode using that button and now I can specify a material from all materials in my scene I'm going to use the red bad material so what this sensor does it says hey whatever I the character touch this material it's going to do something so we're going to connect it to an actuator to make this sensor do something the actuator we're going to use to switch to the screen is called scene we're switching between scenes so we'll click scene and I'm going to connect my sensor to my actuator oops that didn't work thread again and we have another and there and that's okay that's what we want so there's different things that you can do with this scene actuator see an actuator can restart seeing as it does by default right here or you can resume a scene if you've paused maybe suspend a scene which I guess means plausible we talk about that in a later video we can remove a scene sounds a bit dangerous we can add a background scene or overlay scene we'll talk about that too for making like overlays for like a heads-up display or lives or anything like that we can send a new camera or we can set a scene which means changes see if we have a different scenes in our game so I'll click on set scene and right below it we know about area to type in or select what scene we want I'm going to choose my lose scene so basically we just made a logic brick setup for collision if we hit something with a bad red material it's going to take us to the lose screen let's go and check that out I'll press zero on my numpad or go to my View menu and select camera and let's press P to play the game and I'll use my right arrow and as soon as I hit the monkey head BAM I switch scenes and I've made to the lose screen that's what I wanted so that's how you use collision with materials but it's also a way of doing it with properties which might work a little bit better if you have different colored objects that all should do the same thing in other words if I have different monkey heads or different colors that all our bad guys but again they all have different colors on them if I want to do collision detection there's a way of doing that with what's called properties now with the monkey had selected I'm going to give this monkey head a bad-guy property and that's going to identify it as a bad guy I can give the same bad guy property to any other bad guys and then on my character my cube instead of detecting a material for the collision detection I can click that NP button to make it dark I can define a property or selected property from the ones that I've already created and any object with that property will act as a bad guy and it'll go making us go over that you lose screen to do that I'm gonna select my bad guy and I'll give it the bad guy property do that in the logic editor window if I press nml my keyboard to bring up this little side pedal we've always hidden it up until now but it's a good thing we can add game properties here so I'm going to click with the monkey head selected add game property and I'll make this very little bit wider so we can actually see everything that's in there this is where we can add what if you're a programmer you would understand as a variable and there's different kinds of properties or variables the default kind is a float that just means a number that can have decimal places we're not going to use that the one I'm going to use is an integer that seems to work the best for me so I'll use an integer and an integer is just basically a number it's a counting number so if you have a score in your game and it is just using whole numbers where you have lives that uses whole numbers you use an integer value none of that matters oh except using integer we're going to just gonna give this property a name and I'm going to call it bad guy and it's important that you remember what case or how you write it I would not write it with any spaces or capitals or starting with a number out just use one word or a bunch of characters that are not numbers or symbols so I'm keeping it simple bad guy all lowercase and so now in my character instead of using the material bad read or read bat I'll select it and I'm going to use the property bad guy so again under the collision brick with the character selected instead of having the material I'll click on this NP button I'm going to type out unfortunately there is no list here I have to type it as I liked it before bad guy enter so now if I play my game I'll press P and I hit the monkey it's you lose again so there's two ways of making a collision happen and switching between screens you can use either materials or properties depend on which one you want and it is quite simple I'll press escape from my keyboard to make different screens and switch between them that'll make this video thanks for watching and I'll see you next time you
Info
Channel: BornCG
Views: 68,850
Rating: undefined out of 5
Keywords: Game Engine (Software Genre), Game Blender (Video Game Engine), Blender, 3D, game, blender 2.7, tutorial, lesson, learn, teach, help, beginner, dummies, tip, tips, tricks, computer, software, media digital, gamelogic, logic, brick, programming, python, b3d, #b3d, screen, scene, level, switch, collision, hit, hitTest, hittest, touch, property, perperties, variable
Id: -LmM4Snnsao
Channel Id: undefined
Length: 18min 53sec (1133 seconds)
Published: Wed Jun 03 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.