Great tutorial to start 3D Game Development in Unity

As I’ve been interested in game development for a while but never really acted on it I finally took the first step to look around after a good tutorial to get started with, and what engine to use and what not. What I ended up doing was checking out Unity. It is a good engine which is not too complicated and it uses C# so if you are familiar with C-sharp programming you will feel at home when writing scripts! Kind of a tough choice to choose between Unreal Engine and Unity though but since I have been using C# for years it was the natural choice.

Since I only have some experience with XNA back from the good old days when making a simple 2D games my skills are close to none when it comes to game programming. What I did to get some feeling of how it is programming and building games was checking out some YouTube videos to see how people where using Unity to create basic things. This video by Imphenzia is very good, Imphenzia goes through everything in detail of how to get started from scratch with setting up a game.

Next thing I did was checking out the Unity learning website https://learn.unity.com. There is a tutorial in particular that I really liked and it is perfect if you want to explore some of the features of Unity and learn how to do the things you would use in your own game. The tutorial is called John Lemon’s Haunted Jaunt: 3D Beginner tutorial.

It is a very simple but yet powerful tutorial because the tutorial goes through many of the fundamentals of building a 3D game in Unity such as:

  • Pressing keys
  • Movement
  • Character models
  • Animations
  • Scripts
  • Level (already made though)
  • Collisions
  • Triggers
  • Prefabs
  • Camera
  • Navigation Mesh for enemies walking around to certain locations
  • Filters/Effects and lighting
  • Sound

In the tutorial you will make a spooky game from scratch without having to make the character models, animations for the models or the actual level. The purpose is that the character you control have to find the way out of a house and at the same time have ghosts and gargoyles inside the house which you have to avoid! It took me a couple of hours to complete it was well worth the time.

What I found most difficult was probably the Navigation Mesh and the collision part, but I’m sure you have other issues or maybe everything is easy to understand. Can’t wait to make something else on my own!

Here is the result after completing the tutorial

It looks better when building it for Windows though, but you can export your game to web as well which less good graphics. Link: https://play.unity3dusercontent.com/webgl/fc77983e-7c55-4862-b704-917141a6a455?screenshot=false&embedType=embed

Have production and development environment variables

This is how you would have production and development environment variables in a JavaScript nodejs app. I have a back-end nodejs app where I want to connect to a local MySQL server, and when deploying the app to Google Cloud App Engine; have my production settings instead.

First, try and see if you have already have set your enviroment to development:

console.log(process.env.NODE_ENV)

I get undefined, so what we want to do is setting the environment variable to dev when we are on our local computer, and we can do that by modifying our packages.json file where we run our app.

"start": "set NODE_ENV=dev&& node app.js"

Now when running npm start it prints out:
dev

Then download a module called dotenv.

npm i dotenv

Then create a config folder, and add two files: one for your production configuration called prod.env and one for your development configuration called dev.env. See this image with the red circle how my files are created in the folder.

Now I am going to define some properties I want to use for my MySQL connection. For my local development it is going to look like this.

HOST='localhost'
DBUSER='root'
PASSWORD=''
DATABASE='fileideadatabase'
SOCKETPATH=null

Then for my actual production environment configurations I am going to define different values along with SOCKETPATH since I am using Google Cloud SQL to connect from my app in the Google Cloud App Engine.

HOST='12.345.678.90'
DBUSER='root'
PASSWORD='myepicpassword'
DATABASE='fileideadatabase'
SOCKETPATH='/cloudsql/myinstancething:us-central1:fileideaapp'

(There are no commas here watch out writing those!). Okay now we got our environment configurations for both development and production. Let’s load these configurations based on what environment we are in.

if (process.env.NODE_ENV === 'dev') {
    require('dotenv').config({ path: 'config/dev.env' });
}
else {
    require('dotenv').config({ path: 'config/prod.env' });
}

The above code which will check if the environment variable (NODE_ENV) is having the value of Dev, which is has if we start the application locally with npm start which we made sure of in the beginning. The will then continue run the dotenv.config method and load the configuration from the pathconfig/dev.env”. That is the file from inside the folder we created earlier. Same procedure with production.

Most hosting services will change the enviroment variable to production for you so you don’t need to worry about it, for example, if we do: gcloud app deploy NODE_ENV will be set to production thus use the prod.env configurations.

Applying the configuration variables to a MySQL connection like this:

    var mysql = require('mysql');
    let sqlConfig = {
        host: process.env.HOST,
        user: process.env.DBUSER,
        password: process.env.PASSWORD,
        database: process.env.DATABASE
    };
    if (process.env.SOCKETPATH) {
        sqlConfig.socketPath = process.env.SOCKETPATH
    }
    var connection = mysql.createConnection(sqlConfig);

What is worth noting is that we will check if we got the SocketPath property (from the production enviroment variables) is defined or not and put it in to our object as well if it is defined.

Remember to not include your production values in any source control.

You can obviously also add more environments if you got stage etc here as well but this is for how I go about it for the dev and prod environment.