Day 45: Time.deltaTime

I grew up playing on dedicated consoles like the Sega Genesis where a game would run exactly the same no matter whose Sega you played it on.

On PC, developing a game means having to adapt code to run smoothly on virtually an unlimited amount of computer configurations.

This is where the concept of Time.deltaTime comes in. (I’m just reiterating what I’ve learned to solidify the points in my head – feel free to correct me if my understanding on any of the points are wrong)

Let’s say I’m creating a game where I want to move an object at the speed of 6:

public class moveObject : MonoBehaviour
{
     public float speed = 6f;
      
     void Update()
     {
         transform.Translate (speed, 0, 0)
     }

But I’m poor and have a slow computer. It runs the game at 30 frames per second.

FPS (30) * speed (6) = 180 (distance moved)

Someone else has a faster computer. It plays at 55 frames per second.

FPS (55) * speed (6) = 330 (distance moved)

In one second, the game object on the faster computer traveled nearly twice as far in the same time because it called the Update() function 25 more times in one second.

Time.deltaTime is used make this movement frame independent. It represents the time passed in seconds since the last Update().

public class moveObject : MonoBehaviour
{
     public float speed = 6f;
      
     void Update()
     {
         transform.Translate (speed * Time.deltaTime, 0, 0)
     }

My Slow Computer
30 (frames) / 1 (second) = 0.0333333333333333 (time between updates)
Speed * Time.deltaTime =
6 * 0.0333333333333333 = 0.2 (amount moved each frame)
30 FPS * 0.2 = 6 (distance moved each second)

Someone’s Faster Computer
55 (frames) / 1 (second) = 0.0181818181818182
Speed * Time.deltaTime =
6 * 0.0181818181818182 = 0.109090909909091
55 FPS * 0.090909099090909 = 6 (distance moved each second)

Using Time.deltaTime made the distance traveled by the object frame independent. Now no matter how fast or slow your computer runs, it will move at the same rate on screen as another player’s.

The same principle applies on the same computer. If I have a lot of programs running, my game might be running slower at some points and faster at others. Time.deltaTime will smooth the movement of the object instead of it looking twitchy each time Update() is called and the object ‘rushes’ to catch up.

In the same vein of frame rate independency, I also need to learn about FixedUpdate() for physics calculations.

Current Progress Status

  • Tower Defense Tutorial: 47/73
  • Unity in Action (Pg 324 of 352)

Onward!

Day 37: Animator Override Controllers

Youtube comments are generally toxic garbage but sometimes there are exceptions, especially when it comes to tutorials. I’ve found it useful to read through the comments before watching the video to see if anyone has posted any helpful tips or encountered problems.

In video #35 of the Tower Defense tutorial, we’re shown how to animate the enemy characters. After demonstrating how to set up the first monster, we’re directed to repeat the tedious and time consuming process for the remaining three. (It took ~30 minutes just for the first one and it only has an up, down, left and right animation.)

Enter Youtube user “Draven” who informs us of Unity’s Animator Override Controllers which allows us to copy the transitions and animations used from the first monster and apply them to the remainder. (It took less than a minute to create each controller.) It’s a time saving tip that will be very useful in projects going forward!

Animator Override Controllers

Current Progress Status

  • Tower Defense Tutorial: 35/73
  • Unity in Action (Pg 183 of 352)

Onward!

Day 21: Week 3 Recap

This past week I completed the Harvard game dev intro course, specifically the Unity lectures and assignments. Having to read someone else’s code and then make additions & corrections was a good learning exercise. (Casual endless flyer, procedurally generated endless maze)

Unfortunately, I didn’t touch any of my stretch goals for the week. (Honestly, I forgot about that goal until now when I was reading through my last recap. Oopsie.)

Non-coding accomplishments since my last recap included:

For the next week (or two), I’ve decided to go through a couple different Tower Defense tutorials:

The first is from inScope Studios and the second is from Brackeys. I’m interested in seeing how two different developers tackle the same game genre.

Onward!

Day 20: ProBuilder

The final lecture of CS50G course introduced me to new concepts such as Raycasting, Render Texture & Texture Masking. I was also excited to learn about a free Unity tool called ProBuilder which allows you to quickly prototype 3D environments.

Windows -> All packages -> ProBuilder -> Install
(Then ProBuilder will show up under 'Tools')

Next up, I’m planning on following along tutorials from:

I’ll pick and choose game types that I find interesting and just jump in.

If you have any other favorite Youtubers with tutorials about creating Unity games from scratch, please share in the comments.

Onwards!

Day 18: Networking


It’s not what you know, it’s who you know.

A couple former coworkers who have recently gotten better jobs did so because of connections within the new company; they knew someone that already worked there. Without that ‘in’, they wouldn’t have a) known about the unlisted job position b) been selected for an interview.

It’s likely the same within the gaming industry. I need to connect. Listen. Share.

I’ve created a twitter account to get a pulse of what’s going on in that medium, as well as a Discord account so I can chat with others. (PAUSED#8024)

I haven’t gotten around to Facebook yet… maybe I’ll signup for a company page when I start a project. My plan is to start generating interest as soon as possible (Add to to-do list: read about indie game marketing)

Marketing myself is difficult. When I was younger, if I was ever dragged to any house party, I would socialize more with the host’s pets than other people. I’m naturally shy and dislike being the center of attention.

But to be successful, I’ll need to get out of that comfort zone. Put myself out there.

HarvardX: CS50G – Assignment

What I learned by committing some more beginner’s gaffes during the “Dreadhalls” (Hell Maze) assignment:

  1. Make sure to include all the relevant namespaces in the script.

One task was to transition to a “Game Over” scene when the player falls through a hole. Simple enough.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerFallCheck : MonoBehaviour
{
   void Update()
    {   
        if (transform.position.y <= -5)
        {
            SceneManager.LoadScene("Game Over");
        }
    }
}

Why was I getting an error? I checked over the syntax of SceneManager then double-checked I spelled my Scene exactly “Game Over.” I finally discovered I didn’t include the namespace that includes SceneManager at the outset of the script:

  using UnityEngine.SceneManagement;

2. Check the Unity Console often

I attached the playerFallCheck script to my PlayerController so that shortly after it fell through the floor, it would call the ‘Game Over’ scene. Except when I tested it and fell, the character would just continue to fall and fall and fall. The “Game Over” scene was never being called.

I went back to my script thinking the error somehow lay there. Instead, if I had checked the Console first, it was explicitly telling me what was wrong:

Scene 'Game Over' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
 To add a scene to the build settings use the menu File->Build Settings…

Once the ‘Game Over’ scene was added in build settings, everything went smoothly.

Below is how the finished project looks. I shrank the maze considerably so I wasn’t wandering around for too long. Also, because the spawn, end and hole locations are random and the maze itself is procedurally generated, the layout isn’t always the greatest. Okay, enough caveats:

Tomorrow I’ll watch the ‘Portal’ lecture and start that assignment.

Onward!

Day 6: Job Competition

Calgary, Alberta is best known for hosting the ’88 Olympics, cowboy hats and Oil & Gas. The city has never been considered a gaming development hub.

So it was a pleasant surprise when earlier this month New World Interactive announced it will be opening a development studio here in May. The makers of ‘Insurgency’ and ‘Day of Infamy’ plan on hosting job fairs to attract talent and are already accepting applications.

The Calgary studio hopes to expand to up to 50 employees in the next 3 years. Don’t quote me on this but I thought I heard on the radio that they had already received hundreds of applications within days of the announcement.

That’s some tough competition. How would a new would-be developer like myself even hope to land a job in the industry when there are so many more qualified candidates?

I need to work hard and somehow stand out.

New World Interactive uses UE4 for their development (darn!) but I believe if I get a solid understanding of programming and design under my belt, those skills are transferable regardless of the engine used.

Today, I began the Beginner Gameplay Scripting tutorial. I made sure to type out all the code – no copying and pasting.

I’m enjoying this tutorial series because not only does it teach C# but also how it relates specifically to Unity. Some things are beginning to click. That’s a nice feeling.

Onward!

Day 1: 365 Days To A Published Game

I’ve created this devlog as a motivational and accountability tool to keep myself on track.  I’m on the wrong side of my 30’s and in a non-career.  I feel like my life is stuck on pause so I need something to focus on, to create, to move forward.   They say you’re never to old to learn and I’m going to put that adage to the test.

The goal:  to have a game published on Android and/or iOS and/or Steam.  My hope is that a year from now I can look back at the progress I’ve made with pride and perhaps help encourage someone else that finds themselves in a similar position.   The 5-year stretch goal is to become a game developer full-time, either as an indie or part of a studio.

GameSalad, Unity, Unreal Engine, Corona, GameMaker Studio, and Godot are just some of the game engines available

A lot of time has been spent researching which programming engine/language to use.  In the end, I wanted the flexibility to create both 2D and 3D games along with multi-platform developability, so I’ve decided on Unity with C#.    There was plenty of analysis paralysis with this decision.  I just needed to choose something and start programming!

Unity has a lot of tutorials.  But before I jump in with the game engine, I want to lay  down a knowledge base with C#.   The last time I’ve “programmed” anything was over 20 years ago, but the only thing I can actually remember goes even further back – to the days of Apple IIe and BASIC:

10 PRINT "HELLO"
20 GOTO 10
RUN

I remember being fascinated by games like Elite and RoadWar 2000.  My friend had a huge collection of floppy disks (his dad’s) and he would bring them to school for us to play.

Apple IIe
This technological marvel was the pride of my elementary school

Sadly, computers were cost prohibitive back then so I begged my parents for the next best thing: a video game console.  Coleco, Atari, and Intellivision were old news.  There were two new kids on the block.

I stared at that Consumers Distributing catalog for hours, agonizing between the NES and Sega Master System.   The fateful decision made on that day would determine who were my friends and enemies at my elementary school.   Once a side was chosen, I was bound to uphold and vindicate the supremity of that system.  The latest issue of EGM and GamePro would provide fodder for each respective side.

Consumers Distributing ad
The 80’s were a magical time

But I digress. I’ve procrastinated long enough.  It’s time to start on the  journey to become a game developer myself.

I will begin with this free course on Youtube:   C# Tutorial – Full Course for Beginners by Mike Dane.

If you are reading this, feel free to comment and leave your thoughts throughout the journey.

Onward!

Create your website with WordPress.com
Get started
%d bloggers like this: