The basics of creating a ski simulation or game in Unity3D

This is a continuation from our first tutorial on how to import Google Earth terrain into Google Sketchup, and then pull it into Unity 3D.  In this installment, you will actually be able to make a simple, but not fancy, ski simulation, which can be eventually turned into a video game in Unity. This one covers basics of adding a directional light to the terrain, as well as a texture. I then show how to import a prefab skier object, and then assign a Character Controller and Rigidbody to it. Scripts for moving the camera around the skier (MouseOrbit.js – available in Unity Standard Assets) and the skier itself (MoveAround.js) are shown. Other elements such as snow texture and trees are applied to the terrain. And finally, a basic Trail Renderer is shown to give the effect of snow tracks.

Here are the scripts used;
Skier physics/movement: MoveAround.js
Camera movement: MouseOrbit.js

Here is the skier model from Google’s 3D Warehouse: http://sketchup.google.com/3dwarehouse/details?mid=5f527a002f5d7aee4c7bf34a008a31ed&prevstart=24

 YouTube Tutorial

Importing terrain from Google Earth into Unity3D in 5 Steps

Using real terrain in games is just pretty darn cool. The idea of pulling an actual mountain peak which I’ve never skied before into a video game so that I can actually ski it was just too hard for me to resist.  And thanks to Google Earth, it is now possible to pull a 3D mesh of actual terrain into Unity 3D.  Once you are good at this, this can be done in under 10 minutes, and if you know a little about Unity, you can plop a skier onto your new terrain and hit the slopes.

In this example, I pulled a sample skier from Google’s 3D Warehouse, and just added some basic physics to it (which I’ll do a tutorial on shortly).  There is no animation (yet) on this skier, but you get the idea.

To get started All you need to do this is these 3 free apps;

– Google Earth (free)
– Google SketchupPro 8 (they have an 8 hour free trial)
– Unity 3D (free, V3.3 is what I’m using)


Step 1 – Boot up Sketchup Pro

When you go into Google Sketchup Pro 8, first find the button at the top that says “Add Location…”.  Then type in a location in the search bar that you want to map terrain from.  Once it comes up, it maybe a little fuzzy, so click on the minus sign to zoom out about 4 or 5 times.  This will bring you up to around 3 or 4,000 feet above your terrain, which is about right.  Then select the region and click “Grab” to pull in a flat file of terrain data.  Then click a button just to the right of the “Add Location…” button, called “Toggle Terrain”.

 

Step 2 – Export and Save as a FBX file

Once clicked, then boom, you should have a 3D terrain image (e.g. mountain) looking at you. Excited yet?!  I certaintly was the first time I did this. You now need to got to “File” / “Export” / “3D Model…” to save this as a .fbx file.

Note, you may need to try a few locations and altitudes to get all of the terrain that you want.  Also, I suggest importing a square foot-print of terrain so that you have enough playing surface in your game before your character falls off it.

Step 3 – Import Terrain into Unity

OK, now you are ready to open up Unity and view your new fancy terrain mesh. Note, a mesh is a series of triangles that makes up your terrain.  When importing from Google Earth via Sketchup, you won’t be able to get any textures or details, just the mesh itself. Trees, rocks etc you’ll have to “paint” on yourself using Unity’s terrain tools (which are pretty easy and spectacular).

Now go to “Assets” menu (top menu bar), and select “Import New Assets…” and select your .fbx file you saved from Sketchup.  Once done, you will notice that it was plopped into your “Projects” window.  You then can simply drag and drop it into your scene view in Unity. If you left click on it, you will see the mesh made up of thousands of triangles.

Step 4 – Convert your Mesh to a Terrain

You are not quite done yet, but it won’t be long.  You now need to convert your mesh to a “Terrain” object which unity can recognize (so you can paint trees etc onto it).  You’ll need to first import a fancy javascript file to add a menu item to the Terrain menu at the top of Unity.  Save this file: Object2Terrain.js to a folder called “Editor” in your Unity Assets folder.

It must be named exactly like this to work (the folder name is case sensitive).  Once this is done correctly, you will see a new menu item under the “Terrain” pull-down menu at the top called “Object to Terrain”.  But first, you need to go to “Terrain” and click on “Create Terrain” to create a terrain object in the Hierarchy view.  Then click on the actual mesh from the Hierachy view and drag it into the new “Terrain” folder created.  You will see a warning saying “Losing prefab?” or similar, and simply press “OK”.

Now you must click on the actual mesh in the Hierarchy viewing area that is within your new “Terrain” folder, and NOT a parent folder called “Google_Earth_Terrain” or the filename parent folder.  Once you have selected the child mesh in the Hierarchy view, go ahead and select the new “Object to Terrain” menu from the “Terrain” pull-down menu at the top.

Step 5 – Make your Terrain Pretty

Now that you have your newly created terrain, click on the “Terrain” folder in the Hierarchy view.  You will now see a number of options in the “Inspector” tab for painting the terrain with a texture, or adding trees and so on.  When you click on the child mesh itself under your Terrain folder in the Hierarchy view, you will also be able to assign a material (e.g. like snow) to your new terrain.  You can then move onto adding a light source via “Game Object” / “Create Other” / “Directional Light” so you can see textures and trees etc better.  You will likely also want to add a “skybox” so show a sky, add other meshes and so on… until you have created (or recreated) the landscape you are looking for.

PLAY MY HACK!

OK, just look at the terrain…this is Ymir Peak from Whitewater Ski Resort in Nelson, B.C. Canada. OK, just ignore the lack of animation in the skier, the fact that you can ski uphill, bounce off the snow etc.  Just use arrow keys to move around and space to jump.  Again, yes, it’s just a hack for demo purposes so stop laughing… ok, well keep laughing then and go find the cabin at the bottom of the mountain. 🙂

www.alpenglowgames.com/ymir

 YouTube Tutorial