Creating a 3D world and a playable character in Unity3D

Today is the day! It’s time to try to do something in 3D using Unity 3D!

In the old times of XNA I tried to create a game in 3D, building an orthographic camera by myself, and since this day the third dimension is quite frightening to me. With Unity, I decided to give it another opportunity as soon as I can see where almost everything is without compiling the project ten thousand times.

So, this is my first approach to 3D in Unity, with my Unity UI series as a perfect excuse to go deeper into the engine.

First 3D attempt in Unity. Let's go!

First 3D attempt in Unity. Here we go!

Setting up the project

This time it starts like always: File -> New Project… etcetera, etcetera; pretty much the same you have seen in every other Unity tutorial. Once the new clean project is ready, this time I’m using some built in assets to create a good looking environment as fast as possible. To import them, right click on the assets folder at the “Project” tab and select the “Import package” option. Select “skyboxes”, “terrain assets” and “character controller” from the context menu.

Import some Unity packages

Adding some built in packages to the project

Mountains in a few minutes!

Yes, you can create some mountains and elevations using Unity’s terrain editor quite fast and easy. Of course a functional environment for a real game takes much more time than a few minutes, but for an example we can get a good looking terrain with some clicks.

Ok, let’s do it:

  • Create a new terrain: GameObject menu -> 3D -> terrain
  • Select the new terrain object and check the inspector tab. There are some new tools under the Terrain Script component. Pick the first one (raise / lower terrain) and configure however you like.
  • Click on the terrain, drag your mouse and see how it grows a mountain. Holding shift, the terrain gets lowered.
  • Use this tool along the “paint height tool” and “soft height tool” to create some more shapes, and its ready!
Create some awesome mountains using the first three terrain tools

Create some awesome mountains using the first three terrain tools

Painting with textures

With the texture paint tool we can “paint” the terrain with a texture. This texture can be any image loaded as texture to the project, but I’m just using the sand and the cliff texture you can find in the Terrain Assets package. Just click on “Edit Textures” to select the textures assets wanted, and then paint over the terrain like in the other tools.

Adding grass and trees is just the same: select a texture and then just paint over some terrain parts. If the grass or the tree tool doesn’t work, go to the terrain settings and increase the detail distance value to the maximum.

To end with the terrain, create a new directional light (GameObject -> Light -> Directional light) and point it to the terrain to cast some lights and shadows.

texture and grass painting tools

texture and grass painting tools

How to put yourself in your new world

It’s no use to have such good environment if it’s not possible to move around it and see what you have created. Time to set up a way to move yourself through the terrain!

If you look in Assets folder, under a new folder called “Standard Assets” there is a folder with all the files of the Character Controller package we added to the project. Just grab a first person controller prefab and drop it over your terrain and it’s ready, you can move over your terrain using A, S, D, W keys and jump using space.

Be sure the capsule is over the terrain, or the character will fall into the void forever!

There goes our capsule player

There goes our capsule player

Adding an UI to the character

To create an UI, we can just follow the steps of my first post about the new Unity canvas object. A canvas set as overlay will be visible over every object, so if we add some images to the canvas, those images are going to be visible all the time like an in game UI.

A good tip is to create an empty game object to group all the images used in the interface in it. Doing this allows us to add the component “canvas group” to the empty object to control the transparency of all objects of the UI and animate it. For now I’m just lowering it to 0.4.

Setting up a simple character interface

Setting up a simple character interface

BONUS TIP: painting the sky

To finish this post, let’s use the skyboxes package to include a beautiful sky in our example. Under the first person character controller there is a camera where we can add the skyboxes component.  Select the camera object and add a new component to it using the component menu. Go to Rendering -> Skyboxes in the context menu and add a custom material to the new skybox component through the inspector tab. If you added the skyboxes package to the project, you’ll be able to select between some skies options, from sunny to deep nigh.

In next posts I’m improving the UI with some animations and some interactions with the environment, but for now, this is how it looks right now:

Here is the complete list of chapters of this Unity3d canvas series where you can find the entire process:


See you in a few days. Thanks for your time and happy new year!


Leave a Reply

Your email address will not be published. Required fields are marked *