Join Adam Crespi for an in-depth discussion in this video Creating a player controller, part of Unity 5: 3D Essential Training.
- A first step in creating your game is to make a Player Controller. And this way you've got a view point to test from at any point. I'll go into the Standard Assets here in my project window. And again the project window is where we have everything that we can bring into the game. As we can see there's that file structure on the left side. And I'll open this up a little bit. We can see the different folders here. Environment, Cross Platform and so forth. And I'll go into Characters and into First Person Character. There's sub folders within here. And occasionally notes in these Default Assets.
We've got different things in this. There's the Audio, Footsteps and so forth. Scripts that help drive the character movement. And then Prefabs. A Prefab is a really central concept to Unity. I'll go in here and take a quick look. And there's my FPS controller. What this means, the FPS, the first person controller is a view point with movement options that has no character attached to it. We can see in here by selecting it, this Prefab, that its actually got different components on it.
I'm going to look on the right side in the Inspector. And we can see here that its got a Transform and then different components divided in sections. Unity works in a language of Prefabs, things that we bring into the game multiple times sometimes. And components attached to objects or Prefabs like we can see character controllers scripts and so forth. We can also see in here, is that there's different things attached. And I'll drag this first person controller into the scene and check it out. There's two ways to bring things in.
We can either take this first person Prefab straight into the scene. And there's the default capsule. Or, hitting Delete, we can pull it into the hierarchy. The difference in those is that when we pull things into the scene, we are arbitrarily placing. If we pull them into the hierarchy, we're placing them where their transform was when that Prefab was made. I'll click in the scene and then press F to frame in. And there's that first person character. We don't know where it's going to go yet. And we haven't set a spawn point.
But, we've got the first person controller in. So at any point we can hit Play and test our game. Here's what's in the first person controller. We've got a camera and a camera icon in Unity always faces the same direction. But we can see the field of view or rather the cone around it showing where that camera is looking. There's also a capsule, and this capsule defines for us the player bounce. So that when we collide with well, game objects for example, and we can trigger physics. It knows where we are and how big we are in that game.
We can also open this up and take a look at our first person character. In this, by clicking on the first person character now, we get a camera preview saying "here's what we're seeing". And now this is the actual camera control in it. Again, we're seeing a Prefab in here. And we can tell it's a Prefab also by the text being blue in the hierarchy. Now that we've made our first person controller we can change it a little bit if we need. One of the first things I'll change often is the height. Unity units are in meters. And so this person is 1.8 meters tall.
I'm going to bring it down here to 1.7. This puts it at average person height. Not too big and not too small. And definitely not too tall so that we bump into door frames. Size is really important here, because we work in real world scale in meters. So we need to make sure that the character fits our world and the world fits the character. If you'd like, you can experiment with other options in here. Playing with things like Slope limit for example allows you to run up different slopes so we can go very, very high if we're dealing in ladders.
We've also got things in the character like walking speed and running speed. And you may end up configuring these depending on what your game is. This allows you to make your default walking speed faster or slower. Maybe your playing is a turtle or maybe you're being the hair. We can also play with things like jumping, head bobbing if there is, for a more natural motion and so forth. And lastly, we can see when we scroll down, we can associate sounds with it. So that when we have jumps for example, there's a jumping sound and there's a landing sound. We've also got controls in here for things like a rigid body.
And even, audio sources with the characters. This is pretty full-featured as is. It's ready to , well, at least run around and play the game. There isn't anything custom on here yet. There's no actual physical character in here. Or at least sometimes we'll see a pair of arms. There's also nothing associated. No props, no antenna or whatever it is we're dealing with. We've ready to link those in. And we can simply drag them into our character here in the hierarchy to pair it. But for now we've created a character. And at any point we can hit Play and play our game.
When I hit Play, I'm actually falling int the sky. I'm orbiting around by dragging the mouse. And I can use my standard controls. W, A, S and D for forward, side to side and backwards. And, well, I'm not seeing much. It's just the endless sky because there's no objects in here. But having that controller in is really important. And that way you can test your game as soon as you start getting Assets in.
- Setting up the project
- Creating a player controller
- Importing assets, including models, audio, and textures
- Generating colliders
- Creating prefabs
- Applying materials
- Creating animation
- Designing a basic game level
- Lighting the level
- Creating particle systems
- Adding audio
- Building the game for desktop or mobile deployment