 Welcome to Basics of Using Unity for Virtual Reality with Jonathan Bradley, head of studios and innovative technologies. Hello everyone, I'm Dr. Jonathan Bradley and this is the Basics of Unity workshop that we teach here at the University Libraries. Over the course of this workshop, we're gonna talk a little bit about the basics of VR, how to set up a headset within Unity, how to add controllers, movements, interact with objects and we're also gonna go over some of the basics of the Unity editor itself, including how to create terrain, make a world, add scripts to things and we'll also talk about the interface itself and how to customize that. So the next thing on our agenda is to actually download the Unity software. So I'm gonna direct you to go to unity.com. Once there, you should see a screen that looks something like this. On their main page, they usually include a link that says get started. There's also some links that you can follow under some of the other areas, but the get started link will take us where we need to go. Once you've clicked on that, you should end up on a page in which they talk about their various versions. I'm gonna talk a little bit about their licensing structure. So Unity is a professional piece of software. There are versions that you can pay if you are using this professionally, but they do offer a personal license. The rule surrounding their personal license is that it's free as long as you do not use it to make over $100,000 a year. Part of this logic seems to be they want new developers to try their software, to learn it, to be sort of free to practice within Unity, while also having the freedom if you make a successful game and you sell it and it ends up being pulling in a lot of money that you would then ultimately pay for the software and the work that you've done with it. For our purposes, the personal license will be fine. You can also request an educational license if you are using it for educational purposes. You are teaching or using it for classwork. They have information on their site about how to request one of those licenses and it sort of depends on what your use case and needs are. Once you're on the page though, we're gonna click try personal. And it's gonna take us to this picture. They have a terms of service that you have to agree to and you'll see the link here for downloading the Unity Hub. Underneath of that, they list their software's requirements, the OS and some of the GPU information. So check that against whatever computer you're gonna be running it on. If you need computers that are capable of running the software and your laptop or your desktop at home are capable of it, we do check out laptops that have these specs out of the Media Design Studio A within the university libraries. So once you reach the terms of service, use your best judgment, always look through a terms of service and decide if you're okay with agreeing to what they're asking of you. I am, so I'm gonna click agree. And then we're gonna choose a location on your computer. I'm just gonna leave it at the default and hit install. Now we have a sort of a long wait. It's a very complex piece of software. It may pop up with various, okay, installed immediately. It may pop up with various different screens that ask you questions or just sort of handle some of the installation of the business, but whenever you're done you should reach a screen that looks like this. Asking you to run Unity Hub. At which point you can click finish. And it will start. So at this point you have to sign into a Unity account. If you don't have one already, you'll need to click on create Unity ID. For our purposes we already have one. When you click on create Unity ID you'll get a little pop up. It'll ask you most of the standard information your email address, your password, your full name, and deciding on a username. You've got to accept more terms of use and privacy policy information from here. And you can choose whether or not you want to opt into their promotional material. They also have a section down here for signing in with Facebook or Google, which you can choose to do if you prefer to log into systems using an existing account. But once you've set up your ID, you will select your license and we will see you back at this other screen. So after signing into your account you should reach a page that looks something like this. On this page we will actually download and install specific versions of Unity. The system now allows you to install multiple versions and choose previous versions. So depending on what your project is if you need to have a very specific version you can install that one. Or if you need to have multiple versions because you're working on multiple projects you can do so from this screen. For our purposes though we're just going to install the latest version. So we're gonna click this download button. The one at the very top, Unity does its versioning based on year, month and then any given release within there. So you should see our current version of time of recording is 2019, one, zero. That's the one we're gonna click and download. It's gonna ask us a couple questions about some things that we might wanna download along with this. So what kind of components do we want? We want Unity. It's gonna ask about the dev tools. So the one they sort of include by default is Microsoft Visual Studio Community 2017. This is a free piece of software offered by Microsoft and it is where C-sharp development is generally done. You can choose to not install it here and download another piece of software. There are other options if you would prefer not to use this one. There is Visual Studio Code, which is a different IDE that can be used for C-sharp development. And then there are also other possible options that you might look into. For our purposes we're just gonna go ahead and install Visual Studio Code or Community. It is a good piece of software that does a lot of debugging and help for C-sharp. The next section is about what kinds of platforms you think you're gonna be developing for. It also gives you an understanding of just how much space each one of these platforms is gonna take up. So you can make a sort of informed decision about how you might be building to these pieces of software. If you need, if you know you need to build to Mac and Linux, you can go through here and kind of select. And as you can see, there are a number of different options. For the most part, we would always wanna select Windows Build Support and a handful of these other ones that you might be interested in. This one's sort of up to you how much your project might be. You can install these later if you want. So choose sort of the minimum. And if you decide later that you need to be able to build to Android, you can always come back and install. At the very bottom, we've got some documentation and various language packs that you can choose from. We're gonna install the documentation but leave the language packs uninstalled. Once you've selected everything, it gives you a sense of just how big this install file's gonna be. So we can see ours is gonna be 8.3 gigabytes. And once we're ready, we can hit Next. There is another terms and conditions that you have to agree to. This time for Visual Studio 2017 Community since it is a separate piece of software. I'm gonna go ahead and click Agree to that and hit Done. There. So when you're on this screen, you should see a little bar filling up that is telling you how faster download and install of Unity is going. You may get pop-ups as this goes to confirm installation of various things but you can sort of click through those and make decisions as you go. For our purposes, we're just gonna wait until the software installs. So once your version of Unity is installed, you should go to screen that looks a little bit like this. Now that we have it installed, we can go ahead and click New because we're gonna start a new project. You can name your project whatever you want. For our purposes, I'm gonna call it Workshop Example. For template, we wanna choose 3D because we're doing a VR experience, it'll be in 3D. You can choose your location. I'm just gonna leave it as the default. Whenever you create a new project, Unity creates an actual Windows folder or Mac folder and puts all the files in there. It also adds some metadata files on top of that though. So you wanna make sure that if you try to move this, you move the entire folder and not any of the individual folder files inside of it. For organization, you can leave that by default. It'll assign one to your username and then you have this box for enable Unity Analytics. Whether or not you wanna use the Unity Analytics is sort of up to you. It's their way of sort of tracking usage, supposedly anonymously, to see how people are using their software. I'm gonna turn it off for our purposes. Once you've got everything set the way you want, you can hit Create Project. Unity will go ahead and start loading. It'll build up a new project for you and add all the sort of default files that are needed for working within Unity. So we just made a new project in Unity and you were instructed to create a 3D project, not a 2D project. We're gonna go into a little bit of detail about why we chose that because it comes up later as we're working in our project. So a 2D project, if you were to select it, is gonna create a 2D side scrolling sort of project, similar to what you might have run into on old video game consoles. What we are using will be a 3D project and this creates a true three-dimensional environment. The important distinction here is going to be how we add various components. There is a 2D version and a 3D version of many of our physics components and things that exist within Unity. For our purposes, even if we're using an object that isn't itself two-dimensional, like a plane, you'll still choose the 3D physics object version because we're working in a three-dimensional environment, not a two-dimensional one. Once you have gone through and started up your project, you should be confronted with a window that looks a little bit like this. Initially, the Unity interface looks a little bit confusing, but we're gonna go through and sort of talk about the various elements of it, what you do there, and how you might organize and think about this system. The first area that we're gonna look at is the hierarchy and that's this box over here on the left. In this hierarchy is where we keep track of things that we have brought into our scene. You can see the top level of the hierarchy is just sample scene. They create this by default. And we already have a couple of objects in here. We have a main camera and a directional light. Unity adds this to every new project by default. You can think of the camera as sort of your viewpoint into the world. If you would compare it to like a Pixar movie that you might have watched, this is how you as the viewer are seeing the world. The second thing that it adds is a directional light. The directional light is intended to be a sort of all around light source. Without it you wouldn't be able to see anything in the world. You can see both of those are nested under sample scene and that's because they're both children of it. And that's one of the sort of hallmarks of the hierarchy is when you start placing things here you might place one thing underneath of another and make it a child versus its parent and you can have different effects based on doing that. Hi, I'm gonna take a moment and talk to you a little bit about a concept called object-oriented programming. The language behind Unity, C-sharp, uses this concept in the structure of the language. The idea is basically that you can take an object, a sort of a block of code and you can encapsulate it. And then you can build much more larger complex objects by putting together some of these smaller objects into a larger whole. This concept is reflected in Unity in the hierarchy which you'll notice you can make child-parent relationships between various objects. In this way, Unity allows a parent to be composed of numerous child objects that are smaller, more manageable blocks of code. An example of this might be a player character in a world. Your player character, which is gonna be composed of a series of meshes and they're gonna have a certain look to them, is also gonna have a camera associated with it. This camera is going to be the viewport for the physical real-world player to actually see what's going on in the game. In some situations, this may be a third-person perspective where the camera hovers over the shoulder of the player, or it might be from the first-person's perspective where you actually see through the eyes of the character. In both of these situations, the player is the parent to each camera, which is the child. As the player moves through the world, the camera will move with them. And many of the things, including the camera's location in the three-dimensional space, is going to be derived from its parent, the player. The next area of the interface that we're gonna talk about is this window down here at the bottom. This is called the project window. Think of the project window very much like you would a Windows Explorer or the Mac Finder Windows. This window has folders that are part of your project and different files that are within there. You can click on those. You can sort of navigate up and down using the breadcrumbs and the menu over to the left. And this is how you'll find your file. So you can see by default we have an assets folder, which contains a scenes folder. And with that scene is our sample scene that we have defined. We also have a packages folder that Unity adds by default. It has a few of their sort of default tracking packages and things like that. So you can enable things like analytics and UI design. For our purposes though, we're not gonna dig into that packages folder. The other thing that's down here in the project folder, there's a second tab you can see here that's called the console. If you click on that, you'll get a window. This is very much like a terminal. It's best to think of this as where your errors or information that the program has are gonna be sort of spit out. So if you're having trouble running it, if you're getting little messages in this very bottom bar that are highlighted in red, you'll wanna come look at your console. This is where information is gonna be kind of spit out that you can use to debug problems that might have arisen. Currently it's blank because we haven't actually run anything, so we haven't encountered any errors. Next area that is important is this large center area. And as you can see, it has three different tabs. The first one here is scene. The scene is sort of your omnipresent view of the 3D world that you're creating. You can sort of right click and drag around and you can see that it is indeed a 3D world and you are altering your perspective in it. You can see some objects that exist in here. So here is our directional light and over here is our camera. We click on them, we sort of highlight them in the world. In the background, we have a horizon line and below it we have sort of a gray void. Our world is basically empty right now aside from the camera and the light, but this is how we go about editing and placing things. The next tab, which is the game tab, is our viewport into our 3D world. So this is essentially what the camera sees. This is also what will happen if you hit the play button and you start running your program. This, it will automatically switch to the game view and within the game view, you will see any sorts of actions that you have play out in front of you. If you have things move around, they will play in this window. The third tab here is the asset store. The asset store is where you can download various packages that contain anything from sets of code, models, textures, things that you might want to build. Some of the stuff in the asset store is free. Some of it is cost money in order to download and it sort of just varies as you go. This is a great way to sort of get a start on a project looking for some free assets and here in a moment we are gonna show you how to download assets and how to import them into your project. The final main section in the interface is the inspector window. The inspector window is where you can gain information about any given object that's in your world. We're gonna go over here in the hierarchy and we're gonna click the main camera and you'll see when we click it and highlight it, over in the inspector we get a whole slew of information available. You can see that we are looking at the main camera, that's what's listed here in the title of it, but we also have a number of what are called components that are attached to it, each separated by this horizontal line. The first component and what is attached to every game object within Unity is a transform object. All the transform object generally does is define its place and size within a three-dimensional world. So you can see we have our position, our rotation and our scale of this object and these all operate on the XYZ Cartesian plane. So X and Y being forward and backwards and Z being up and down. You can type numbers into here to move objects to very specific locations. This can be very handy for locating lost objects and moving them quickly to your origin or your center which is zero, zero, zero. You can also work with finer detail on things like rotation and scale to ensure that objects are exactly the way you want them versus trying to do it manually by dragging arrows and stuff around. In addition to the transform component, there is also a camera component attached to the camera. This is a Unity-based component. It is sort of created for you and when you add a component object or a camera object, you get the camera component automatically attached. It has a handful of properties that you can change and alter depending on what your needs are, including an audio listener component, a skybox information, clipping and physical camera components. All of these things are intended to give you more control and give you options that you can check or change numerical values of to alter the way your program runs. So that is sort of our interface for Unity and what each individual component does and we're getting ready to jump into actually adding some various things to our 3D world like terrain and different asset packages that we'll use to control our VR experience. Now we're gonna talk a little bit about asset packages. In Unity, there is an asset store and it's composed of things that you might need for a project that you're working on in Unity. These assets can contain anything from particle physics code that someone else has written, 3D models and meshes and audio clips. Asset packages can also be composed of multiple different types to produce some sort of given effect that you might be looking for. In Unity's asset store, some of these things are free and some of them you have to pay for. All right, so the next step in our process is gonna be to go ahead and download some packages that we need for this project. For this particular tutorial, we're gonna be working with an HTC Vive headset and we're gonna be working within the SteamVR platform. So the first thing that we're gonna need to do is download the SteamVR plugin. So if you go to the asset store window, you should see a search box and if you type in SteamVR, all one word, the top option that pops up should say SteamVR plugin. You're looking for the one that is from Valve Corporation which is the company who actually designs the interface for SteamVR. We're gonna click on that. You'll be taken to the page for the SteamVR plugin and over on the right hand side, you should see a button that says download. We're gonna go ahead and click that and Unity will go ahead and start downloading this plugin. Once it's downloaded, it'll do a little bit of decrypting and preparing the files but the download button should then turn into an import button. Note here that if you have already done work with SteamVR and you've already downloaded this plugin, you may not have to download it again. It may immediately show you the import button. Either way, you're looking for it to say import and we will go ahead and click on that now. At this point, Unity will start preparing the package. It'll start pulling all the different components out of it and organizing them and getting ready to add them to your project. All right, once you've imported and Unity has sort of decompressed your files, you should get a window that pops up that looks like this. It's importing the Unity package. So a given package may include many different resources. You may only need certain ones and it can be beneficial to only import what you actually will need to help keep your ultimate file size of your project down and make it sort of build faster and be more efficient. So for our purposes right now, we're gonna look through this list and we're gonna import everything. If you are actually doing a project that you wanted to build and distribute in some sort of public fashion, it would be worth your while to go through here and uncheck anything that you're not actually using in your project and only import those things that you actually need. But like I said, for this tutorial, we're gonna go ahead and import everything. So once you've seen the list here, you can click this import button in the bottom right hand corner. Unity will take all of the files that you've selected and add them to a folder in your project. So once it's complete, you can look down here into the project folder at the bottom of the screen and under assets, your top most level folder, you will have a new folder that is called SteamVR. I'm gonna take a break while it compile. So once you've imported and added the folder, you may get a window that pops up that looks like this. There are some settings that are okay for a normal video game to have that are not very good for VR. They can do things like cause, motion sickness. So SteamVR, once it detects that you've imported it and added to the project, we'll check your default settings and ask you to change some of them, particularly ones that are not very good for SteamVR. So it'll pop up and ask you if you wanna go ahead and change these settings. We're gonna click accept all. In general, these are good things to be accepting for VR. So we wanna go ahead and do that. It'll change a couple of your settings and it will tell you that you made the right choice. Very positive reinforcement. So you can see now in our project window we have a SteamVR folder. If we click through it, we will see that there are a ton of different folders, different plugins and things that we can take advantage of now. We're gonna dive into that a little bit more in a second of which of those plugins, which of those files are gonna be relevant to this particular project. But before that, we need one more asset package. And this one is called the Unity Essentials. So we're gonna type in Standard Assets. And what you'll see is once you type in Standard Assets, the very top plugin that shows up is called Standard Assets. And it's actually made by Unity Technologies, the creator of the software. The Standard Assets package just contains a lot of good models and scripts for someone who's learning this piece of software. We're gonna download it because it has some good tree models and some good textures for grass and rocks and things along those lines that we're gonna use in our project. Once you've found it, you can click on it. And from here on out, the process is very similar to what it was for SteamVR. We're gonna download and then we're gonna import this into our project. All right, so once we've imported all of our assets, the next thing we're gonna do is actually make some terrain, a world for our game to inhabit. So we're gonna come up here into the hierarchy and we're gonna right-click and go down to 3D Object. Underneath the 3D Object submenu, you'll see Terrain as an option. We're gonna click on that and you should see a very large white checkerboard pattern appear in your 3D world. You can zoom out and see that it is a very, very large area. This is on purpose. This is your game world that we're gonna sort of edit and we want it to be very large as possible. For our purposes, however, we wanna move our game world and try to place it a little bit more centered on our zero, zero, zero. So our cameras and everything appear in the center of this. So have your terrain highlighted. You should see a box pop up. On this box, there's a red, a blue and a green arrow representing the XYZ coordinates. We're gonna click on these arrows and if we drag them in the world, we'll actually move this object in the given direction that they're pointing. So we're gonna click on this red arrow. We're gonna move our area back. We're gonna click on the blue one. Also move it back so it's sort of centered. You can zoom back in using your center mouse wheel to sort of get back to your center point. We'll make some fine tune adjustments, but the goal is to have the center of the terrain very close to the center of the origin plane, which is zero, zero, zero and also where our camera and our light are currently located. All right. So now we have the terrain sort of centered on our origin point and you can see that the camera and the light are back into the scene. Over here in our hierarchy, we have a new object called terrain that is at the same level as our main camera and our directional light. First thing I wanna show you is a little bit about this hierarchy and how you can subset things as children below them and what happens if you accidentally do this. So if we grab our terrain, we click on it and we drag it. If we drag it over directional light and drop it, you'll see that it's now indented underneath of there and we get a little error at directional light that we can close. This means the terrain is a child of the directional light. If we were to drag this directional light, the terrain would actually follow it and move with it as you can see here. That's because anything that happens to the parent where they're gonna try to translate to the child. This can be very helpful for things like cameras. If you want a camera to follow a specific object through the world, but it's also fairly easy to do on accident when you're putting things into the world. So if you accidentally make something, the child of another object within the hierarchy and you don't want it to be, you can simply click on it and drag it and instead of dragging it over the object, you can drag it between there and instead of highlighting directional light, you'll see we get a little line between directional light and main camera. If we let go now, terrain actually is no longer a child of directional light. You can see it's on the same level in the hierarchy as main character and directional light and they're no longer tied in that fashion and terrain will move independently of the directional light. So now that we have our terrain in the world, it's time to sort of make it interesting. It's fairly blank. There's a little bit of a checkerboard pattern, but this isn't a world that you would necessarily want to hang out in. So the first thing we're gonna do is actually raise and lower our terrain. This is how we make hills and mountains and gullies and things along those lines. So with our terrain highlighted over here on the right-hand side in the inspector window, you should see under terrain a few different options. The first one over here on the left, if you highlight over it says create neighbor terrains. We're gonna click on that button. Within this button you'll see the, it gives you some directions. It says click the edges to create neighbor terrains. So we're gonna go ahead and... So now the terrain has been moved to the top layer of the hierarchy and it is on the same level as main camera and directional light. So now that we have our terrain in here, it's time to sort of paint and shape our terrain to make it actually look like a world. Currently it's perfectly flat and it has a little bit of a checkerboard pattern, but it's not a kind of world that you would necessarily wanna interact with. So we're gonna go over here to terrain and highlight it. Over on the right-hand side in the inspector window, you're gonna see the terrain object. We're gonna click on this second object in this set of tabs that says paint terrain. Once you hit that button, you'll see a sub window pop up and there's a little drop down here. By default it should say raise or lower terrain, but you can always, if it doesn't, hit the drop down and check it from that list. Now, once we have that, we're gonna wanna take a look at our brushes. So this portion of the process looks very much like sort of using Photoshop if you've ever used that. You're gonna choose a brush, we're gonna choose its size and we're actually going to paint onto that terrain and it's gonna alter by raising and lowering that space to make things like hills and mountains. So the default brush is a very large semi-solid circle. For our purposes, we might choose one of these other ones that are a little bit smaller and we're gonna drag down our brush size a little bit so it's not quite as large. So you can see they sort of show you in the preview window what sorts of mountains and peaks you might get from using this brush. We can also change our opacity and here in this situation, opacity is going to dictate how strong of an effect clicking and painting is going to have. So if we want very strong peaks, then we might turn the opacity up. If we want a little smaller, more gradual change, we might turn the opacity down. So I'm actually gonna turn mine down to about 20 here and I'm gonna start painting. So as I click, you can see the world starts sort of raising up. The checkerboard pattern is intended to show you how that typography is actually changing. For this scenario, I'm actually gonna start sort of draw a circle around our main camera origin area where the walls are tall enough that it would be difficult for the player to see over them. And this is a pretty common thing in game design. We sort of have a tendency to move the horizon so that you can't really see it, add things like mountains and hills and rolling things so that you've kind of broken up that flat line on the horizon so that people can't sort of get over that and run to that void that's off the edge of our terrain. So you can see I've sort of made a little bowl. You can adjust these in any way, shape, or form you want. You can create great mountains in the distance if you want. You can also smooth them out by sort of changing your brush and altering them in a few ways. If you go to the dropdown menu, you can see we have some other options. You can set a height. If you have an exact height you need it to go to. But the one we're gonna look for right here is called smooth height. And this gives us another brush that we can play with. And this is just gonna sort of even out some of these sharp peaks and make it a little bit more natural, especially if you're not going for like a craggy mountaintop. So it'll sort of start to even out some of this spacing and make it look a little bit more natural. We're gonna just sort of tap on a few areas where we got some particularly sharp peaks. You can sort of hold in your mouse and run it over this entire area. And it'll sort of smooth and even everything out. But it sort of depends on what sort of environment you're looking for. So we have a pretty good setup here. We've got a set of terrain with a circular border around it. But it still doesn't look quite right. If we hit this play button here in the center of the screen, we'll switch over to game mode and we'll start seeing things through the camera. And if you look through the camera at what we're seeing, it doesn't look very realistic or necessarily appetizing to play. So every now and then you'll get this pop up from SteamVR. Unity likes to change some of the settings back. And SteamVR will continue to check them in a cert and make sure that everything is set up well for VR play. So just click accept all whenever it pops up just to make sure that it's getting it setting set properly for VR. But this is sort of our game views. You can see nothing really happens if you right click in this area, you can usually move the camera around sort of get a better view of the vicinity that you're in. But right now we're just sort of looking and the checkerboard pattern is unrealistic. So let's make it look a little bit more like grass. You wanna uncheck this play button. One note about the play button in Unity while you're in play mode, you can feel free to change things, add different settings and adjust these options over here in the inspector window for any of your objects. And you should see these changes happen in real time. Problem is any changes you make will be undone whenever you hit the stop button here on the top bar, which is clicking on the play button again. The reason why they do this is the play time, the play runtime is essentially for you to try things out and see how they work. That therefore the changes you make are not permanent. So anything that you change, if you actually end up liking what it is, you need to make a note of what that value is and be prepared to enter it again whenever you leave play mode. So we're out of play mode now and we're back at our editing screen. We're gonna go over to our terrain section in the inspector window. We're gonna hit our dropdown. In our dropdown we have paint texture and that's what we're gonna select for this section. This is gonna allow us to apply that sort of consistent color to our terrain and texture to give it a sense of being grass or some other material. Once we've selected that, we wanna go down here to edit terrain layers, click on that and hit create layer. Once you hit create layer, you'll get a little pop-up window that looks like this where we're gonna select our 2D texture. For our purposes you can search and we're just gonna click and type in grass so that we can filter out all the other textures that are included in this. From the grass options that are left, we're gonna check grass, hill, albedo. We're gonna click on that and sort of double click on it and it will add it to our project. You can see by default the first one you select gets applied to the entire terrain. So now we have this particular texture applied to everything we've got so far. So it looks a little bit more realistic. You can also see that it's been added to the project over here under terrain layers. But we wanna add more. We made some mountains and rolling hills and it doesn't really make sense that those would be grass. So we're gonna go over here to edit terrain layers. We're gonna click on this button and we're gonna hit create layer. Under this search we're gonna actually type in rock. What comes up here is we've got grass, rock, albedo and that's the one we're gonna select. So we're gonna double click on that and you're gonna see it's added to our project but it's not gonna change what's already there in any way. This has given us the opportunity to sort of decide where we might want this rocky texture to be applied. So by clicking on it and having it selected, you can see it's sort of outlined in blue now. We can go in with our paintbrush which you can still edit down in the right hand side under brushes if you want. We're gonna sort of start painting this new texture layer over the existing. As we do this, you can see the green of our grass is sort of getting overwritten by this rocky brown. This will allow us to sort of go over some of these peaks and lower rocky areas and give them a little bit different texture. So it implies, you know, this is rocks, these are hills, these are not just grass covered knolls. We're gonna sort of paint all of these and you can sort of play around with this section for as long as you want to get the look you're going for. But once we've painted that, we're gonna go into play mode and take a look now. So we're gonna click this play button in the center of the screen. Once you're in play mode, you should be able to see this different textures applied to our mountainous area. So we have our green center valley, but we also have some sort of rocky mountains in the distance with a different texture applied to them. If we look, we can see some areas where there's a little bit more green than maybe we would want and you can go back in and play with this more. You can paint and sort of color over some of these areas to get the consistent look that you might want, but you can see how we're starting to blend these various colors to make a very basic terrain. So we've returned to the scene window and we've got our area. We're gonna do one more thing before we start working in VR. We're gonna add some trees. We have some rocks, we have some textures applied, but the world still seems very flat and uninteresting. Next thing we're gonna do is over here in the terrain window, beside the paint terrain button, there's a paint trees button and we're gonna click on that. Once you click on that, you'll see a large window pop up here that says for us to define our trees. So under our trees, you can see we don't currently have any defined. We can click on this button that says edit trees. We're gonna click on add trees from the sub menu. Once you click on add tree, you get a new window that pops up. Here we're gonna do a predefined object that looks like a tree that we're gonna paint a whole forest of the sort of randomly assigns them to make them look a little bit realistic. We don't currently have a tree selected. So we're actually gonna click this small circle right here and it's gonna bring up a menu of our assets and we can sort of search. In our package, we're gonna search for broadleaf to find this broadleaf tree model that is included in our standard assets package. So I'm just gonna check on one of those and double click. You'll see it fills in with this tree prefab and we're gonna click the add button down here in the bottom corner. So you can see back in the right hand side, we now have a tree placed in our listing. We once again, we have a brush that we can go through here and paint and this sort of will let us largely fill in trees. So as we click to paint with this brush and drag it, you'll see trees begin filling in almost like a forest in random order, sort of give a sense of realism and we can sort of start placing those around the world as we want. You can also change how you want these trees to appear in these settings on the right hand side. So we can change our brush size and make it much smaller or very large. We can change our tree density if we want a light forest or planes or if we want a very dense wooded forest, we can adjust that here. Our tree height sort of comes in at random but you can set a threshold for that by using these sliders and you can also do things like randomize the tree rotation and alter the colors on the tree's model slightly to give more realism to the forest that you're building. There's also this mass place trees button that will just place trees across your entire terrain and this is a great way if you're building forest map to just quickly get trees placed everywhere throughout the world. We've gone ahead and placed a few in this world and that's gonna be good for sort of setting up this barrier. If you want, you can always go in here and sort of edit them down. You can use the undo menu, which is control Z to get rid of them. If you place too many or you place them in a spot you don't want and you can always make the brush a lot smaller if you wanna paint them in a smaller area. But we now have a world with some trees in the background. Once you've hit the play button, the world will load up and you can see we now have trees in the distance. They sort of randomly placed and add a little bit of character to our world. The tree painting button is not have to be just trees though. If you want things like rocks or three dimensional grass you can also use this tool for that as well and you'll just choose those models from the standard assets package or from whatever asset package you may have or from assets that you created yourself and sort of use the same tools to randomize and paint them across your landscape. That is a great way to easily give your world depth that your characters can see and interact with and do it easily without meticulously placing every blade of grass or tree in your world. So in this next section, we're gonna talk about a concept called prefabs and I'm gonna go into a little bit of detail about that now. So say you were building a game, maybe it's a zombie game and you know that you're gonna have hundreds and hundreds of zombies that exist within your world but your zombies are gonna be a complex object. They're gonna have a mesh, they're gonna have a collider, they're gonna have scripts on them that tell them how to behave, how to find a player, how to take certain actions, they're gonna have animations, they're gonna have a very complex structure in our hierarchy. So you go through the trouble of making that object but then you need to make it a hundred more times. Creating a prefab is a way of taking a complex object that you've created once and making a copy of that whole structure. So one of the convenient things about doing things this way is that we don't have to recreate things every time we wanna use it and it also allows you to distribute these sort of pre-created objects to people which is what we're getting ready to get into in the next section. All right, so we have a terrain built here. It's very basic but you can spend a lot of time playing with this and trying to make a terrain that fits the world that you're interested in. You can also bring in other models that you've created and pull them into this world as well. But what we're gonna move on to now is pulling the actual headset into the world. We talked a little bit earlier about the main camera. The main camera currently acts as a 2D entrance into the world. We're gonna go ahead and actually delete that by right clicking it and going down to delete. The reason we're getting rid of the main camera is because it's only a 2D window into the world. We need a VR headset to actually be brought in. VR relies on two cameras to sort of render out each eye and give a depth of field to the world around you. In order to do that, we're gonna use a prefab or a sort of prefabricated object that has a lot of associated items with it that is produced by the headset manufacturers themselves. Nice thing about this is we don't have to worry about the code that controls the headset, the controllers, the menus, and all of that sort of thing that's associated with a VR headset. And we can sort of get down to developing. Part of the reason why companies do this is they wanna make it as easy as possible for developers to bring in the necessary controls and objects for working with their headset so that they don't have to write special code to deal with it. This makes it more likely that developers will wanna use your hardware and ultimately make builds that can use the hardware. For our purposes, though, it makes our job a lot easier. So the next thing we're gonna do is we're gonna go down here to our project, a window. We're gonna click on our assets folder and you should see everything we've sort of entered in here. We're gonna go into our Steam VR folder and we're gonna go into the interaction system folder that's underneath of that. Underneath of that, there is a folder called core. We're gonna double click and finally prefabs. We went in, cause I actually wanted to see, show you the true location of this prefab. You can always use this search bar, though, in the future to type in files if you know they exist to have it sort of search your project for them. But what we're looking for here is the player prefab, which you can find in this folder. We're gonna drag the player prefab up here into the hierarchy. There's two ultimate ways that you can drag an object into your world. You can drag it directly into the hierarchy or you can drag it into your scene. In most situations, you probably wanna drag it into the hierarchy. This has a tendency to place it at 0, 0, 0 in the world and makes it a lot more difficult to sort of lose the object that you're dragging into the world and keep track of where things are. There are a handful of reasons, though, why you might wanna drag something directly into the scene. And we'll get into those a little bit later. For now, though, we're gonna drag this into our sample scene in the hierarchy and drop it. You'll see it appears in our hierarchy and it also appears in the scene at 0, 0, 0 near where our camera and our light source are. This player object has a lot associated with it and you can see what all's associated with it by clicking this little collapsible arrow. We've got input modules that have controllers, steam VR objects that have things like colliders, left and right hands, VR cameras. There's sort of a lot going on here. The most important components of this is a player collider. This collider is essentially a field that is around a given object, generally in a shape that you can use to programmatically decide when something touches another thing in your world. This is particularly useful for creating interactions between two given objects that you've added. The player object that you add already has a collider set up for it. I wanna take a moment now and talk about colliders. Colliders are a physics component that we can add to objects that will allow the system to know when two objects are touching. One of the important things about colliders is the shape of them. So you'll notice in our player prefab that the player is made up of a lot of simple shapes. So a capsule for the torso, a sphere for the head, maybe some capsules for the arms and legs, and maybe a square with some capsules attached to it for the fingers. There's a reason they do it this way. Using a true mesh in which the actual shape of the character is the collider itself, it can be computationally expensive. And what I mean by that is it will tax the graphics processing unit in your computer to the point where it could potentially start dropping frames. And in a VR experience, if you start dropping frames, this can lead to things like motion sickness. So in many situations, it's better to design a more complex collider by putting together simple shapes. In the end, you'll get a very similar performance, but you won't tax your graphics processing unit nearly as badly. There's also controllers and there's the VR headset itself, which includes an audio listener. This means that any audio that you place throughout the world, the headset will pick up and transmit to the headphones that are attached to it. So you don't have to worry about setting up your own audio listeners for the headset either. They'll pick up any sort of audio sources that you've added to the world. So we've got our player object. And at this point, if we had a headset plugged up to our computer and we hit the play button, it would actually go ahead and run this program within the headset. The headset would have the controllers that are associated with it and a set of hands that models that are associated with them. So in a very easy drag and drop sort of way, we've got a headset in our world that's being managed and controlled by code that we were given by the manufacturers. In this section, we're gonna be adding scripts to individual objects within our world. Scripts are C-sharp code that can come from numerous different places. They may come from the asset store as part of plugins or packages that we've downloaded. They may come as part of the system itself or we may write them ourselves and add them to the system. It is important to note however that all of the functionality we've been dealing with up until this point, including the light component, the camera component is C-sharp code. It just happens to have been written for us by the manufacturers of the software. But it is there and can be manipulated if we so choose to. All right, so we have our player object in the world which includes our headset and controllers. Next thing we wanna do is add a fairly simple object that we can manipulate. So we're gonna go over here to our hierarchy. We're gonna right click and we're gonna go down to 3D object. We're gonna add a cube. When we click on cube, you'll see it appear in the world. It's sort of floating near our player and our lights and our camera and everything. It adds a number of things to it that we can see here in the inspector including a mesh render which shows it as a white plane cube. If you wanna change what it looks like, you can do so here. The other thing it adds is a box collider and this collider will allow us to actually detect when we are interacting with the cube and take some sort of action based on that. Let's talk to you a moment about physics in the world. So if we take an object and we add it to our world, say we take a simple sphere and drop it in. That object, while it exists and we have a way of viewing it, doesn't understand the physics of this world just yet. If we were to start our game, this object would just float. It doesn't know that gravity exists and it doesn't understand that it should react in that way and it doesn't really respond to any sort of physical interaction that would knock it somewhere or tell it to behave in a certain way. What we do is we add a thing called a rigid body to that object which gives it a sense of the physics of the world. We can check that we want it to pay attention to gravity in which case as we start the game, the ball falls and it rolls and it behaves as you would expect a ball to behave. So if you have slanted terrain, it will roll to the lowest portion of that or if it's flat, it may bounce a couple of times and stay still. The important thing to remember here is that adding objects to the world doesn't necessarily make them behave like an object in the real world would. We have to actually add that functionality ourselves. So now that we have our cube in the world, we wanna make sure that it has a understanding of the physical world. If we hit play right now and we observe the cube, we will see that it isn't affected by gravity. It just sort of eerily floats in mid air, seemingly unaffected by the world around it. That's not particularly realistic if we want this object to seem like a cube that somebody might encounter. So in this scenario, we may want to add physics to it. If we go back to the sample scene and make sure that cube is highlighted, we're gonna go over here on the right-hand side and we're gonna add a component. When we hit add a component, we're gonna start adding these different properties, essentially, to this object. The one we want for this particular scenario is called a rigid body. So if we start typing in rigid body, you'll see it filter out all of the things that don't match and we get rigid body. An important note here is that we have the option between a rigid body and a rigid body 2D. For physical objects like this, you always wanna choose the non-2D object when working in VR. The 2D is only for if we selected 2D at that main screen. This is true even if the thing you're making appears to be a 2D object such as a plane. We always wanna select the non-2D object because we are not in a 2D environment. So we're gonna select rigid body and add it. By adding the rigid body to the cube, we have given it an understanding of physics. There's a physics engine built into Unity that sort of handles the real-world interactions that objects that have. And once we add a rigid body, there's a few details and properties of the physics that we can change, including its mass, the drag, its angular drag, whether it's affected by gravity, whether it's affected by things like explosions and other things along those lines. All of these you can sort of detail in the documentation about what each one does, but you can also just sort of play around with them as well. At this point, if we hit play, you'll see the cube actually falls out of mid-air and lands gently on the ground. This is because it now has an understanding of physics and floating objects generally are affected by gravity. So we have a cube and it's now understood by physics. But we need it to understand how it needs to interact with our controllers. We wanna be able to pick it up, look at it, move it around, rotate it as we use our controllers to touch things in the world. So we're gonna add another component by going to the Inspector window, clicking Add Component. Now, instead of rigid body, we're gonna search for interactable. You can see from our list, we have a script here called interactable and this is code that's been written by the manufacturer for interacting with cubes and other objects that you might add to the world. Essentially, this script attached to an object held SteamVR and its controllers, this is a thing that controllers can interact with. They should be able to pick things up and deal with them. So when we click on it, we'll see it get added. There's a handful of options that appear on this script as well, things like how to attach it to controllers, how, what your range of motion is, and some of the animations for when you grab or release things. This allows us to actually pick up a cube, hold it in midair, but when we let go of it, it will go back to the place it was picked up from originally. If we want this object to behave a little bit more like a real object in the world, something that could be picked up and then possibly thrown, there's another script that we'll add. Under Add Components, we'll add throwable. You'll see that we have a couple different options for throwable scripts. We're gonna choose the regular throwable one. When we add the throwable script, you see it actually adds to a velocity estimator in which you can make some physical adjustments to what the velocity will be when the object is thrown, and the throwable script itself, which has a handful of other options that can be played with. At this point, when we pick up the cube and we let go of it, we can actually toss it across the world or it will tumble and come to a rest as per the physics would dictate, given its shape and mass. I'm gonna talk to you a moment about locomotion within VR. In traditional video game experiences, we often use a joystick to move around the world. We push it in a given direction and the player sort of glides or moves in that direction. This can be a little bit troubling for VR, however. Sort of pushing on a joystick and having your character move in that direction will give differing senses to your body. Your eyes will perceive movement through the world as you move through the VR world. However, physically, there'll be no inertia on your body, and this disconnect can often cause things like motion sickness. Better than using a joystick, we often recommend people use teleportation to get around in a virtual world. Teleportation, which comes sort of enabled within the plugins that we're using for this given workshop, is a better form and allows to go longer distances and has less disconnect between what the brain is sensing and what the body feels like it should be physically experiencing. The third method of locomotion in VR is actual physical movement. Some VR headsets offer a walking or room scale experience. In those situations, players can physically move up to a certain distance within a confined space. What that distance is depends on the headset and the way the room is set up, but this physical movement is the most natural and realistic movement and should be utilized whenever possible. It, however, has limitations and prevents people from going long distances within VR experiences, and that's where teleportation can really help out. To add teleportation to our world, we're going to go into our project folder down at the bottom of the screen. We're going to start at our top folder, the assets, and click on Steam VR. In Steam VR, we're going to go to our interaction system folder, and instead of going to core like we did last time, we're going to go to teleport. And within teleport, we're going to our prefabs. In our prefabs folder, there is a teleport prefab. We're just going to take this and go ahead and drag it into our hierarchy. The teleport prefab is required to enable teleportation within the world, but it is actually not, you can't teleport yet. You still have to tell it how you want to teleport. The teleporting object is here to sort of define how teleportation is going to work. So if we click on it and highlight it, you can see over here on the right-hand side, the teleport script has a large number of options that can be tweaked in order to adjust how teleportation happens. Some of these options include the color of the teleportation safe zone, the color of the invalid teleportation areas, the arc that your controller uses when it points out, the distances that act as a maximum teleportation distance, things like audio sounds when you're teleporting and fade in and fade out effects for teleportation. All of these are adjusted on this teleport script. But to actually define how we want to teleport, we've got a couple of options we need to choose from. One of those options is to provide predefined teleport points. These points will give people specific locations that they can teleport and are primarily used when you want to control where people can actually explore and not give them sort of a more open sandbox that they can move around in. If we want to add teleport points to our world, we're actually already in the folder we need to be in. In the teleport folder and the prefabs, there is teleport point right here. This is a scenario in which if we click on teleport point and drag it, we may want to drag it into the scene. We can sort of go ahead and place the teleport points near the places we want people to be able to go. And by dragging it in the scene, we can see the exact location. Whereas if we were using the numbers and trying to put them into the hierarchy, we would have to do a lot of guesswork. So I'm gonna go ahead and drag a teleport point into the world and drop it. You don't have to have just one though. You can drag as many of these as you would like into the world and place them in different locations that you want people to be able to go to. At this point, if we enter the headset and we use the controllers, we can push the teleport button on the controller and actually point it to these various locations. Once we're pointing at them, they will highlight green as valid teleportation points. And when we release the button, we will instantly be teleported to them. So that's how you add teleport points to the world. But that's a little bit limiting. What if we wanna give people a whole area that they can teleport around? Well, there is a thing called teleport area and that's what we're getting ready to add as well. So we're back in our world. We still have our teleport points, but we're gonna try to add an actual area. You can notice there's nothing else in this prefabs folder for teleport area. And that's because we sort of have to create the plane that we would like to make accessible. So over here on the left-hand side in the hierarchy, we're gonna right-click, go down to 3D object and add a plane. You can see a plane gets added to our world. It's sort of high, so right now it's standing above some of our other objects. So one of the tricks with the teleport plane when you add it to the world is we generally want it to be as low to the ground as possible. This keeps it from interfering with other objects and sort of blocking them when you're pointing controllers at things. So we've got our teleport plane in here. We've lowered it down below our cube and below some of our other objects. And you can see it sort of hovering just above the floor. With the teleport plane highlighted in the hierarchy, we're gonna go over to the right and we're gonna add a component. We're gonna type into the search bar, teleport, and we're gonna get some options. The one we're looking for here is teleport area. We're gonna select it and click on it. You'll notice that as soon as you add teleport area to this object, it becomes transparent. That's because you don't actually see the plane unless you're attempting to teleport. So under normal circumstances, it is invisible. An important aspect to consider though when it comes to a teleport area is that you need it to not go below the terrain itself. If the teleport area drops below the terrain itself, it will be hidden and you won't actually be able to select it when you're trying to choose a point to go to. So we wanna make sure it's just above that plane. You can adjust this by making multiple teleport planes, especially if you have a very rocky or uneven surface to sort of adjust and make sure that the entire area you want people to be able to go to is made available and is visible to the controllers as they attempt to teleport. So at this point, if we hit the play button, we'll go into the world. We can use the controllers to do the same thing we were doing before, but now we have a much larger area that is available for us to teleport around. This gives us a little bit more freedom. You can extend this plane as well. You can scale it to be far longer or far wider than you want. We could essentially make the entire terrain a valid teleportation area and let people decide how far they wanna go. In general, you only wanna give people access to things that you want them to be able to do in VR though. So once you have this section of the workshop down, you may say, I really wanna get into something more complex. I wanna add abilities to objects and interactions that are beyond the things that are provided to me by the headset manufacturer. To go beyond, you're probably gonna wanna learn a programming language. For Unity, we use C-Sharp, which is a language that's primarily maintained by Microsoft. It's a fairly easy language to learn in comparison to other languages that are used in video game development. There are plenty of resources online for learning this language. You can also look at GitHub for versions of code that do very common tasks that are commonly associated in video games and VR experiences. Because people regularly write these things, they often create open repositories for this code so that it can be shared between similar projects without having to rework and rewrite things from scratch. So once your project is finished and you're ready to build an executable that other people can try and install in their machines, you'll do that from the file menu. You'll go down to build settings, at which point you'll choose how you're going to build the project. You can choose the platform, whether it's PC, Mac, Linux, or some mobile devices or for the web. You'll choose that from the menu that's provided. You'll also add scenes to your build. If you've only got one scene, it will often add that automatically, or you can add all open scenes to this project. You can choose some of the details about it, including process or architecture and things like that. That can get into some more advanced things, and if you need more information, please check the Unity documentation. Once you're ready, there's a button down at the bottom that says build that you can hit and it will build your project. At that point, it will create an executable file in whatever formats you've chosen that you can then distribute for use. This concludes our workshop. Thank you for watching. If you need further help, please visit our website, lib.bt.edu, or stop by the Virtual Environment Studio on the fourth floor of Newman Library to get more help.