Pagina's

Wednesday 27 February 2019

In-between project: Oxford Street

As I told, I go to work by bus every day and that gives me time to work on little projects. Little ones, because my laptop is as slow as can be.

I wanted to make a small endless runner game with no strings attached. And I wanted it to be about something of consequence, so enter my trip to London, a couple of months ago.

It's been ages since I went to London and now that I'm legally adult and married, I thought I could enjoy the city more, so I took my wife by train from The Netherlands to Kings Cross station. We passed the Harry Potter wall thing and went to our appartment for the week.

Nice city and all and I can really recommend the British Museum, but that did not give me the idea to make this game. My wife came up with the inspiration, as she wanted to go to Oxford Street with me for her lady time, which she deserved. Problem was that it was Black Friday. Enter the endless runner where you are me or my wife and you need to evade people in the busy shopping street.


This is my first build of my first complete game and I already found a bug, but that's in the most unimportant thing I could imagine. Who in their right mind would ever want to exit this masterpiece? (hint: use the Windows close window cross thing).

So, all this being said, with a combination of shame and pride, I present you Oxford Street, where you need to evade the shopping people.

Here's the link to the installer. If it should not work, please leave a reply behing and I'll fix it.

Sunday 24 February 2019

I'm on the outside

A new <Russian accent>great success</Russian accent> in my game. I managed to have animations to control and I have a system that knows and shows whether the player enters or leaves a location. It took me an evening and a morning, but now it works.

First I needed to get a grip on how animations work. I saw a couple of videos about making doors open and close, but they all had a little problem in that they focusses on the door itself and I wanted to have the pivot of the door control it open, so I didn't need to move the door, just rotate the pivot. That worked fine, but I got to have a lot of work in the animator component, because the door could not close after being opened, immediately slammed shut after opening or it kept repeating the animations (the health system luckily did not react to being smashed between the door). Now I found out how to fix that.

Second is a generic inside/outside trigger system that I'm certainly going to use a lot in the future. There's a box collider that the player needs to go through to get to a location (just past the door, on the side of a village etc.). It notices if the player passes it and if it's relevant to act on it. If theplayer is outside the building and passes the Outside-trigger, it does nothing, but if it gets inside and passes the inside trigger, a boolean value will change and understand that passing the outside trigger will mean something else.

Here it is in action:

Thursday 21 February 2019

Drowning

Being a genius, sometimes ideas just pop up in my head in the bus or somewhere else. While I was pushing it ahead until I had enough of a grasp of how Unity deals with these issues, I found out a way to detect the player is in the water. There's a problem with just detecting collision with the water, because water is kind of just the surface and when the pond gets deep enough for the player to be inside it, below the surface of the water and not touching it, things are difficult.

The ingenious thing I came up with is this:

The thing on the right is a meassuring stick and the stick figure is the First Person Controller in the game. The blue semicircle is the water. What I came up with is a system with a dual Collider under the surface of the water. The purple "Water" collider and the red "Deep water" one. 

Because normal gravity rules do not apply to water bodies (we don't just walk over the bottom and up the banks), we have something detecting that, while not having the extra drowning perks. the collider is half the size of the FPC, so it'll allow the player to keep his/her head above the surface, literally. When the player drops to the red zone, the same gravity rules apply, but there are some more perks, including a timer that starts running. When the timer hits a certain level, the player is out of oxigen and health will drop quickly.

Another thing, nice idea from my colleague Annika, when the player is in the red zone, the UI will get a semi-transparant blue mask to have it visually obvious we're in a dangerous spot.

Other things I'll put in there will be about slowness and the possibility to fight, with some way to move up and down (probably by jumping-a-like behaviour). And probably more, but that's for later.

Wednesday 20 February 2019

Refactoring and the minimap

In these tutorials, the people always say they need to change existing code to deal with new things that came up later in the project. Well, why don't you program them right in the first place?

I am a programmer, so I know that the choices you make can come back to bite you in the long run, but that is the long run. In the short run, one makes the right deci... So I started refactoring the mechanics for controlling the inventory. Now I have a red ball and a blue ball to pick up and a updatable list to contain them both. The madness.

Furthermore, I found out about the Render texture to make a minimap. I might use a squad object to have more symbolic representations, but we'll see. That's for later.



One of the next things I'm going to focus on is opening and closing doors. I already put some code in the scripts for player interaction with other objects, and I need to get it to work. Make my first real Unity animation and have the player move through an opening or into a new scene.

Monday 18 February 2019

Health and Fatigue

Now for the category "it does not look like much, but man did I put a lot of effort in!" I managed to get a health bar and an energy bar in my GUI and it looks decent to start with.


It works alright as it will update on any chance in either health or energy. The bar will get smaller if we lose health or energy which is nice and most importantly, my rubber duck wife immediately knew what it meant and started asking the questions that I answer with "that's going to happen, but does not happen yet."

Will you drop dead once the red bar is empty? Can you still jump when you don't have any more energy, What if the enemy is not tired and you are? Still a lot to do.

Next and easiest will be to have the energy drop when sprinting, which the player already can do. I might have the fatigue play a role determining the speed or jump force, but I'll have to experiment with that. Furthermore, I hope to have a Minimap in the UI. Maybe the head bob, but that's a lower priority.

After that, I'm going to focus on the mechanics and see if we can get things to hurt the player and have the red bar drop a bit.

Friday 15 February 2019

Another project

Ok, they say we need to finish our projects. I know. On the other hand, they also say it needs to be fun and feeling rewarding and it's a good thing to have a massive list of little goals to hit on the way to finishing the project, so I'm starting another one. A first person RPG adventure game in 3D.

Before making it look awesome, I'm focussing on the mechanics like a basic First Person Controller with a crosshair and my first experiments with raycasts that I'm pretty pleased with. Even though it isn't big, it's nice to see that the player will detect an object that is tagged PickUp and within a certain distance from the player and that when we press E, the object will disappear.



Next, I'll do a bit of GUI with a health bar and a fatigue bar and something in the world to affect those values. After that, I'm going to work on the basic inventory and find a way for the player to have some head bobbing when moving. Hopefully I'll be able to hit these goals in the days to come.

I'm starting to like this stuff more and more.

Sunday 10 February 2019

A collision problem with monsters and walls

Alright, I knew the monster would come back to bite me and it's giving me problems. I had a factory script build me a small 10x10 level which looks like this:


The stick figure in the left bottom corner, that's me. There's a couple of walls, a door, a health box and two monsters. I already made a script allowing the stick figure to walk through the level using keys, avoiding the walls and the door.

Now I added a script (bottom of this post) to the Monster class that makes it walk in a random direction (up, down, left or right) until it hits a collider. Then it decides another random direction (never the one it was already going) and moves on. I have this script. Note that Monster inherits from Enemy. All Enemy does is make sure a variable level contains an animation from the factory class. That happens in the base Awake.

This code results in the two monsters moving which is correct. The monster in the middle-right of the screen will go up and down and the one at the top will start moving places until it gets stuck in a corner like this:


As you see in the code, I added a Debug.Log to find out what is happening and it appears that the monster not only collides with the wall to its left and top, but also the one to the top-left.  I suspect that the monster had its direction until it hit one of those walls, backs off in the OnCollisionEnter2D function and decides to hit the other two walls.

My question is if there's a way to get this thing to work: when the moveDir is decided, can the script predict immediate collisions without triggering them? I have this thing in the DecideMoveDir-method where I make sure the randomNumber is never the same as previousNumber so that the monster does not re-bump into the wall and get stuck. Can I broaden this while loop (or other thing) to make sure the resulting moveDir does not cause problems?

Or, maybe I'm just thinking wrong, does this phenomenon have another cause? Is that fixable? All I want to have here is the monsters walking in a random direction and chancing course randomly when they hit a wall, a door or each other. When they hit the player, something else will have to happen, but that's gonna be ugly.

Here's the entire Monster class script:

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

public class Monster : Enemy
{
    private Sprite[] currentAnimation;
    private int currentFrame = 0;
    private float frameRate = .2f;
    private float timer;
    private SpriteRenderer spriteRenderer;

    public Sprite[] monsterIdleAnimation;
    private Vector3 moveDir;
    private float speed = 2f;
    private float speedTimer;
    private int previousNumber;
    

    protected override void Awake()
    {
        base.Awake();
        monsterIdleAnimation = level.monsterIdleAnimation;
        HealthSystem healthSystem = new HealthSystem(50);

        currentAnimation = monsterIdleAnimation;
        spriteRenderer = gameObject.GetComponent<SpriteRenderer>();

        moveDir = DecideMoveDir();
    }

    void Update()
    {
        MoveMonster(moveDir);
        DecideMonsterAnimation();
        AnimateMonster();
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        Debug.Log(gameObject.name + " / " + collision.gameObject.name + " nr:" + previousNumber);
        transform.position -= moveDir;

        moveDir = DecideMoveDir();
    }

    private int RandomNumberGenerator(int a, int b)
    {
        int getal = Random.Range(a, b);
        return getal;
    }

    private Vector3 DecideMoveDir()
    {
        Vector3 direction = new Vector3();

        //nooit twee keer dezelfde richting bepalen.
        int randomNumber = RandomNumberGenerator(1, 4);
        while (randomNumber == previousNumber)
        {
            randomNumber = RandomNumberGenerator(1, 4);
        }
        previousNumber = randomNumber;

        switch (randomNumber)
        {
            case 1:
                direction = Vector3.up;
                break;
            case 2:
                direction = Vector3.down;
                break;
            case 3:
                direction = Vector3.left;
                break;
            case 4:
                direction = Vector3.right;
                break;
            default:
                direction = Vector3.zero;
                break;
        }

        direction *= speed * Time.deltaTime;
        return direction;
    }

    public void MoveMonster(Vector3 direction)
    {
        transform.position += moveDir;
    }

    private void DecideMonsterAnimation()
    {
         //does nothing yet.
    }

    private void AnimateMonster()
    {
        timer += Time.deltaTime;
        if (timer >= frameRate)
        {
            timer -= frameRate;
            currentFrame = (currentFrame + 1) % currentAnimation.Length;
            spriteRenderer.sprite = currentAnimation[currentFrame];
        }
    }
}


Saturday 9 February 2019

Sorry about the monster

I told you so! Graphic design is my lifelong nemesis. I think I'm fine drawing anything to the level of advanced stick figures, but what I gave the world today, that is scary! I needed an enemy for my hero, so I drew a monster:


I am so sorry. Nobody should have to go through this. And the worst thing is that this is going to be the monster for the time being.


Friday 8 February 2019

My top-down RPG-adventure

Well, it's not going to be Skyrim yet and it does not include anything like a massive world, as far as I can foresee, but I got to building my first game yesterday evening. It's going to be a simple top-down game with my stick figure walking around.

I have my walking pixel art stick figure prancing around with a lot of #swag, according to my colleagues and this is our hero. It is he who will make his enemies tremble in fear and it is he who is going to open doors, pick up health potions and, most importantly, guide my programming advancement.

I have figured out how to make use of this animation via a style sheet and how to have him walk to a certain location, from the Unity Codemonkey tutorials. I also made a simple level building system to add wall objects from a small PNG file to the scene in Unity. I might need to tweak that a bit, but I have enough of that for the time being. 

Next will be creating the Stick Figure object and adding all its components. I'll pobably need prefabs for that (and for the walls too), so I'll have to focus my efforts to this matter, this weekend. Hopefully, there'll be a basic character system by the end of the weekend and then I can start making more of these nice animations too.

Wednesday 6 February 2019

Let's get started

So this is what I am going to do. I'm taking on game development and I'm going to be a game king of some sort, but first I need to get learning.

My name is Tommy and I'm a historian and a full time software developer. I make boring stuff for companies to do their administrative work. All well and nice and it gets food on the table, but a man's got to do what a man's got to do, so insert this blog.

I'm going to make games using C# and Unity. I'll be making my own crappy graphics (because while I can program and will get used to C# and Unity, drawing is my lifelong enemy, so I'll take it on) and designing all of it on my own.

Sitting in the bus to and from the office gives me time to think and blog and I'll try to write down my thoughts regularly. I hope it will help me through the projects and I hope it will be fun to read.

YouTube people all tell me I should keep my ideas small. I'm thinking about making Skyrim or Age of Empires though. Thinking mostly, because that's what I do. I'll try not to let it get to my head,  but bear with me, because it's hard. I'm sure. 

For now,  I'll mostly be trying and studying and building something small. Hopefully I'll be able to release something and progress as we go, with my epic RPG or strong  RTS in the back of my head. Probably something historical or fantasy-context in the long run, but with stick figures to start with.

I hope it'll be fun!