Steady Drop – Log #8 – Tutorial

The value of the tutorial

It’s been awhile since the last devlog and from there I’ve been struggling so much in the project to create a proper tutorial.

At some point in the development (probably too late) I started thinking a way to explain to the player the main mechanics and  what are the goals of the game. There are a lot of ways of doing that (I’ve done my homework) and I thought that a short tutorial, at the first try, before starting the game, could be a good way to proceed.

I wanted a tutorial to explain the input basics and the main mechanics to the player, so in this section all the points and the game logics (talked here) and the spawn logic (talked here) have to work in a different way.

 

I started to work on this with a specific approach where the entire tutorial is a level slot (here I talk what I mean for slot) but this wasn’t really suitable for what I had in mind, so after almost forcing myself to try and develop a tutorial system that works in that way, I realize that it ain’t gonna work, so I deleted everything and started the tutorial system from scratch. After some time and some struggling, I finally have a tutorial system that “kinda” works. It’s still pretty rough but It does its job so I can refine it after the launch of the game alpha.

 

The biggest advice I want to leave is to consider designing the game and the code with a tutorial in mind, if you want one. The fact I didn’t think at all to the tutorial at the beginning of the development made me waste a lot of time to refactoring my code and redesign the levels. So, keep the rules simple and keep a simple way to explain it to the player right from the beginning of the development.

 

I think the alpha version of the game will be available in early january 2017. Stay tuned 🙂

I define myself as a creative developer.

LD36 Post Mortem

 

With a little delay, I will write a short post-mortem for my first Ludum Dare I’ve ever done.

Preparing for the jam

I live in Italy and August is a “ghost month” since everyone are in vacation… After some unfortunate team searching I decided to partecipate to the compo (which lasts 48 hours) also because the jam was 72 hour long and I had to work until Monday night which was not possible for me. The main rule of the compo is that all the work has to be done by one person, so I jumped in the compo by myself.

Since I was doing all the work, I started to set up my workstation at home and my software environment for coding with Unity, making 2D assets with Gimp, making sound effects with Sfxr and making music with LMMS. Ok ready, all set. Let’s start! The theme? Ancient technology.

 

What went right

It was my first time on doing all the work (programming, art, music & sfx) and I’m pretty happy on how I faced this challenge, but not completely on the final results. The workflow I used was very smooth and I scheduled all the task with meaning. I’ve the opportunity once again to test my skills and expose all the things I’m good at, and also the things I need to work on. After all the experience was very challenging in a good way and I’ve learned new concepts that I can reuse in my future projects.

 

What went wrong

First of all the time, but not the remaining time. I mean the time zone: in this jam everyone starts at the same time regardless of your time zone, and since I live in Europe I started my jam at 3am. So the lack of sleep influenced the rest of the jam for sure.

Secondly the theme was a hard one for me, so I struggled in the beginning for finding an idea, and I end up with using a poor game-logic idea. At some point during the event I thought to quit the jam and rest, I felt really stressed and I wasn’t sure if I was able to continue, but fortunately after a little nap I carried on.

I was recording my screen to do a time lapse (like I did for the last GGJ) but sadly after some hours of work since I thought to quit I stopped the recording and I hadn’t turned on again, so no time-lapse video this time.

 

Tips for the future:

  • Concentrate more on the theme.
  • Try to come up with a game logic that has the theme involved, not just mentioned.
  • Spend more time on choosing the graphic style.
  • Sleep more during the event.

 

Final Result

This time the results of all the efforts was Titus Discovery (ld36 entry). I think I won’t work on new features or bugs, we will see.

 

 

I define myself as a creative developer.

Steady Drop – Log #7 – Project Structure

 

In this post I will talk about how I put everything together and a little bit of code management.

Code versioning

Let’s begin with some things to remember: use a versioning system…and again, use a versioning system. I can’t stress this enough. Really, for every project you’re working on, use a versioning system like Git, SVN or Mercurial. It really helps keeping the project managed and it’s necessary for collaboration with other people. If you don’t know what is a repository you can start here.

My habit is to use repositories especially for work and since I saw more benefit using it I decided to use them on my side projects. For Steady Drop I used Git on BitBucket with only one branch (for now) it really helped me also giving more value of what I developed and I will develop.

 

Project structure

In the beginning the files are not well organized and the project was a little mess. At the time the code was really messed up and disorganized, since I started from a prototype. After some refactoring sessions, the code was more readable and clear but I still had one problem: the organization of the files (both scripts and assets).

I started to re-organize the project (with some Unity guidelines) doing a lot of folders to separate logically the assets and the scripts, but I wanted more for the scripts. So, I started to separate the scripts and to do a lot of folders. I was not sure if this approach could work out but then I started to separate the “core” scripts and the game specific scripts, finally giving a more meaningful project structure.

 

Reuse core modules

All that core scripts are inside a specific package so in the future I can take this package and use it in another project. But what is the best way to do it without going crazy on maintaining a “fork-like” package? Recently at work I started to use the git submodules which basically are repository that can be inserted in an existing repository (like an inception of repositories 😀 ), and I thought that I can create a module with all the core stuff and reuse it in different projects. This change will be the next “project-side” improvement and since I have already experience with multiple submodules in one project so, it will be a piece of cake to set things up for only one module.

 

Alpha is coming

The alpha of the game is going to be released in the next couple of months. The best way for me to release it is to give it to a restricted set of people, (like friends and relatives) and gather feedbacks from them. Then I will iterate once again to make things better and put some others features in the game to create (some day) a beta version.

 

 

I define myself as a creative developer.

Third Person Camera with Unity

 

The third person camera

The camera in a game is the eye that the player use to see inside the virtual world created for the game itself. There are tons of different types of camera, but the one we are going to analyze is the third person camera (TPC from now on) which allows to see the main character moving around in the world. In our case it’s a camera that follows the player. Great examples of games that use this type of camera are Super Mario 64, Zelda – The Wind Waker, Metal Gear Solid and Assassin’s Creed.

The purpose of this article is to show how to do a camera system in Unity, with basic intelligence that follows the player and avoids to hit walls by doing auto-adjustments of the distance from the player and the ground as well. The final results are not the best ones and there are certainly other and better ways to do it, and yes, I know there are some improvements that can be done, but the main purpose of this demonstration is to give a simple starting point.

Setups

The Unity script is located here. The only things you have to do in order to test the script are:

  • In a new Unity scene add a third person controller. You can use the standard ones
  • Add at least one floor.
  • Add a child GameObject to the controller called “target” for example, and position it where you want the camera to look.
  • Add a child GameObject to the controller called “position” to identify the position of the character: some meshes may have the anchor point positioned differently, so in this way you can decide the correct position of the anchor point. It’s a optional step but it makes things a little easier.
  • Add the script to the camera and put the child objects just created under the camera script parameters in the inspector.

The code is commented and contains also a function to draw lines in the inspector to better see what is going on with the offsets and positions.

Camera position and movements

Without further ado, let’s begin with the fun stuff. The wanted position for the camera is a point that has a distanceUp and a distanceAway from the target identifying a specific point. Obviously if there is a rotation of the character, this point rotate along with it keeping its distances. Now this point is only the wanted position and we want the camera to follow this point with a little of smoothness. Simple, in positioning phase I’ve multiplied Time.deltaTime for a smoothness value.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public void Update()
{
    //For collision avoidance we need 2 values:
    // the distanceUp of the camera and the wanted position

    Vector3 characterOffset = m_target.position +
    new Vector3(0f, m_distanceUp - m_heightOffset, 0f);

    drawDebugLines (characterOffset);
    m_camPosWanted = m_target.position +
        (m_target.up * (m_distanceUp - m_heightOffset)) -
        (m_target.forward * m_distanceAway);

    collisionAvoidance(characterOffset, ref m_camPosWanted);

    //Positionig and orienting the camera
    transform.position = Vector3.Lerp(transform.position,
    m_camPosWanted, Time.deltaTime * m_smooth);

    transform.LookAt(m_target);
}

 

The collision avoidance

To keep the camera in the correct position and avoid walls that can hide the character or collide, the script makes some tests:

  • Wall avoidance: if there’s a collider near the back of the character or between the camera and the character, the camera takes the position of the collision point (improvable).
  • Ceiling avoidance: if there’s a collider above the character or above the camera, the camera changes its y coordinates to stay under the collider.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//Camera Wall avoidance - raycast from the back of the character and from
//characterOffset to camPosWanted
if(Physics.Linecast(fromObject, toTarget, out m_hitWall) ||
   Physics.Raycast(m_characterPos.transform.position,
   -m_characterPos.transform.forward, out m_hitWall, 3.0f))
    {
        toTarget = new Vector3(m_hitWall.point.x, toTarget.y, m_hitWall.point.z);
    }

    //Camera Ceil avoidance - raycast from the up of the character and from
    //the up of the camera
    if (Physics.Raycast(transform.position, Vector3.up,out m_hitUp, 1.0f) ||
    Physics.Raycast (m_characterPos.transform.position, Vector3.up, out m_hitUp, 2.0f))
    {
        if (m_hitUp.collider.gameObject.layer != LayerMask.NameToLayer("Player"))
        {
           if (m_camPosWanted.y > m_hitUp.distance)
           {
               Debug.Log("Ceil");
               m_heightOffset += 0.2f; //adjusting the height
           }
       }
    }

Improvements

Improvements that can be surely done are:

  • Making a FSM and attaching it to the camera: for example the camera has state like colliding, shaking, bouncing and a following common state.
  • Improving the wall collision not to see parts of the world behind the wall.
  • Adding a colliding sphere to the camera.

 

Consider also to watching this GDC video on which a creator of the game Journey talks about common mistakes and tips on creating a third person camera.

Source code

https://gist.github.com/plafone/6ed1f2edf37108bc18a7
 

 

I define myself as a creative developer.

Steady Drop – Log #6 – 2D Art

 

This post on Steady Drop development is about the art process and choices I’ve made.

Minimal style

During the pre-production phase I wrote down all the possible styles I could develop for Steady Drop, and like I said in one of the first posts, I was thinking to give to my game a cartoonish-like style, similar to Cut The Rope, just to mention a famous example. I finally chose a minimal style in order to emphasize the gameplay and reduce the distractions and also because it is easy to maintain.

Since the style I wanted was really simple and minimalistic, I started to create the assets on my own. I’m not an artist, but this type of style is something I’m able to work with. I wanted the main focus to be game logic and gameplay so I eliminated the unneeded and went back to the roots: the shapes and the colors. I think that sometimes all we need to recognize an object is its shape and its color, so every element in Steady Drop has its particular (geometric) shape and its inner color. I regret a bit this choice but it makes possible to speed up the assets production and allows me to concentrate more on the development.

 

The need of using a vectorial format

Having a minimalistic and geometric style for all the graphic assets led me to think using a vectorial format. The pros of using a vectorial instead of a lossy format are quite important on both technical and design side:

  • Smaller file size.
  • Changing resolution without loosing details.
  • The sharpness of the shapes are always very neat.

 

Obviously this pros are applied for my project, you don’t always need a vectorial format. I grabbed my favourite vectorial editor and I created some ideas of objects and actors of the game. And after some concepts and a lot of inspiration sessions, I came up with the (almost) final version (posted here). The problem at this stage was: I could possibly take advantage of a vectorial format in Unity?

 

Using the SVG importer

To solve this issue, I tried to find a way to use natively a vectorial format in Unity but unfortunately Unity (version 5.4) does not support vectorial formats, at least I haven’t found a native support. So, I started looking on the assets store and I found this (SVG Importer). Basically this tool imports a SVG file and convert it in meshes (I think one for any visible closed path), keeping the quality of the shapes at any resolution, I thinks even retina displays. The integration was very easy with no code required and the results are very good and I’m happy with it. I’ve only one little issue on replacing a svg texture at runtime but I solved it with a little workaround.

 

The next post will be on putting everything together and on code management. Stay tuned 🙂

I define myself as a creative developer.

Steady Drop – Log #5 – Game Input

 

Gyroscope handling

I want to talk a little bit about the first things I developed when I got the idea for Steady Drop. Just from the beginning I had this idea to use the gyroscope data from a mobile device and to do something with it. I started developing a first prototype which uses the gyroscope quaternion given by the “attitude” property and elaborating it to get the gravity direction using euler angles. The class doing all this stuff was (and is) called GyroTilt and for some time the name of the game/project was GyroTilt until I came up with Steady Drop. For a prototype it worked fine, and I started developing the game on top of this logic. At the time I wasn’t testing everything so often on a real device and for a reason or another I finished up screwing part of the logic and all the rotations were broken.

Recently I’ve changed the method to compute the gravity direction by simply getting the gravity directly from the the gyroscope class. This property returns a vector (with magnitude one) with the direction of the gravity in world space. I can take this vector and go on and use it with the rest of the logic which wants only the gravity direction and ignores how it is computed. Unexpectedly this gravity vector is much more stable that the attitude and I think it is not more CPU expensive that the other.

One issue I will have to resolve will probably be the device compatibility, since I’m developing this game for Android, there are hundreds of different devices with different mounted sensors. I haven’t tested my game on different devices yet, so I’m thinking to give the game build to some friends and people who can test it out, a sort of “closed alpha”.

 

Gravity direction, now what?

Ok, now that I have the gravity direction I use it for adding the increasing force (like I said in devlog #4) with its logic ruled by user inputs, and for rotating the object. To rotate the object correctly, I tried in the first place to use the RigidBody rotation caused by the force I add, which is nice but I could not find the right level of responsiveness I want. So I decided to freeze the rotation on the RigidBody component and to apply the rotation manually to the Transform. In this way the rotations are very responsive and the fact that I’m not using the rotation from the RigidBody is not a problem, since the physic system is all custom and ruled from my scripts.

 

Future uses

Since now the gravity direction seems stable I’m thinking to use the gravity for different purposes that can add gameplay variationsRight now the only object that react to gravity is the avatar of the player, what about some special enemy that reacts to gravity? I’m not sure to use the pendulum that I have right now, but I’m thinking a new type of walls maybe, that reacts to gravity. Maybe the gravity can affect some physics parameters of an object or an obstacle. I will decide what to do about this matter in the future, surely after the beta release.
Stay tuned for future posts 🙂

I define myself as a creative developer.

Steady Drop – Log #4 – Game Logic

 

Like I said in the last post, this one is about game logic.

I think games can be a pretty good simulation of the real world, and so far they do a really good job in this, even if most of the times there are only approximation of physics rules. Again, they CAN be a simulation but they do not HAVE to. So, in my case, I choose not to follow the stricts physics rules of gravity but I defined my own one.

 

Gravity logic

What I have at this point is only the gravity direction ruled by the device orientation. The amount of gravity force is determined by a simple algorithm: starting from a base multiplier, I add a certain value to this multiplier every N crossed unit and then I multiply the gravity vector for this multiplier.  In this way the speed increases in a sort of exponential way.

When the player stops the gravity, current force and speed are saved and they are applied once the player release the stop.

 

Point Logic

Let’s start with explaining the basic idea. I wanted a scoring system based on the distance that increases the points every N crossed game unit. The amount of increase depends on different factors. It depends on the gravity multiplier explained above and on a point multiplier that is progressively lerped to zero when the player stops the gravity and lerped to a maximum value when the player doesn’t stop the gravity. In this way a long stop equals to a smaller point increase, especially for high gravity multipliers. If you stop at the beginning there’s no big deal because the gravity multiplier is still low.

To do a recap:

  • Increase points every N crossed game unit .
  • The increase depends on the gravity multiplier and the elapsed time .
  • The gravity causes speed, which implies that the points are added more often.

 

Obviously, user-side the only things to be told are to keep falling as smoothly as possible and try to avoid to stopping too often. It seems a complex system but it’s not and it adds a certain level of unpredictability for the player.

The health is the maximum gravity stop time

The game world:

  • leaves room to the player to do basically whatever he wants
  • it’s “analogic”: the actions are not sampled or fixed

 

I need a system to connect all the aspects (gravity, health, score) together. I started to think about something that can affect the gravity, the points and the gameplay as well, and I think to bring in the time, too. We can stop the gravity with all the effects on point multiplier discussed earlier. But for how long we can stop it? Well…for a time related to the remaining health of the player! When stopping the gravity, a bar shows the player that the time is decreasing. When the available time is zero the time it starts to load but the player can stop the gravity again only when the time reaches the maximum value (the remaining health). I came up with this idea pretty far in the development but it is something that connects everything and I developed it.

This kind of relationship between stop time and health holds up everything giving importance to every aspects of the gameplay.

For visualization I choose two overlaid bars. When the time is increasing or decreasing the player sees the above bar that scales down or up revealing the bottom bar that represents health. In the image you can see the bar that represents health (green) and the stop time bar (lime-yellow) when the time is decreasing.

Schermata 2016-07-10 alle 14.03.30

 

This covers pretty much everything on game logics and since this time was a lot talking, I decided to give something visual as well. These are the current versions of the game actors. I think they will be the final ones, more or less. You can see the color palette I decided to use too.

actorScreen

 

 

I define myself as a creative developer.

Steady Drop – Log #3 – Level design

 

It’s been a while since the last devlog. I had some other projects to follow and a lot of stuff to do, but here I am. Let’s jump right into the subject: this post is about level design and my approach to level design in Steady Drop.

 

Level procedural creation

In this I started to think about full procedural generation where I put the rules into the algorithm and the level are generated with no manual level design at all. Sure, great approach, but I’ve found is not really suitable for what I wanted to do. Since the only level I have is potentially infinite I though more like a sequential loading.

Eventually I came out with a type of sequential loading where the level is loaded from basic parts that I call “slot”. The slots are loaded when needed progressively as long as the character falls down and are deleted/disabled when are offscreen because they are not usable anymore. The main operations of loading and deleting is shown in this code snippets below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public void spawnNext(float fallObjYOffset){
    if (fallObjYOffset > m_CurrentYOffset - 10) //if I'm almost there
    {
        //pick the right pool
        List<Env> currDiffEnvs = m_OrderedEnvs[m_CurrDiff.ToString()];
       
        //pick a random slot of the pool
        int eIndex;
        do{
            eIndex = Random.Range(0, currDiffEnvs.Count);
        } while(eIndex == m_LastIndex && currDiffEnvs.Count > 1);
        m_LastIndex = eIndex;
       
        //load the slot
        GameObject env = GameObject.Instantiate(currDiffEnvs[eIndex].gameObject,
                                                new Vector3(0f, -m_CurrentYOffset, -3f),
                                                Quaternion.identity) as GameObject;
        m_SpawnedObj.Add(env);
        env.transform.SetParent(transform);
        m_CurrentYOffset += envs[eIndex].offset;
        m_Spawns++;
    }
    if(m_Spawns == m_DiffSpawnSlot)
    {
        modifyDiff(1);
        m_Spawns = 0;
    }
    disableVeryFar(fallObjYOffset);
}

Basically, the slots are divided by difficulty in different pools and since the difficulty is progressively increased as the player goes down, a random slot are picked from a pool of the current difficultyIn this way each slot has to be independent from others and still give a sense of flow and continuity when put in a slot chain, so I had to find a easy method to create a set of separate slots that convey flow.

 

Level design

In the last couple of months I started to read about different techniques of level design along with image composition, functional level design, “level design has to serve the gameplay” and others best practices and tips on the matter.

Finally, I found that this approach on Gamasutra could be very suitable for what I was trying to achieve, and you will find references of it in the following explanation of my level design pipeline.

Basically what I’ve done are very simple few steps.

  1. Defining the component palette: all the enemies, obstacles and even the player.
  2. Divide a blank sheet on three and drawing a curved path on each part. This is my ideal falling path, my flow.
  3. Mark the points of the path that are on the center and draw a horizontal line. In this way the horizontal line delineate a slot.
  4. Populate every slot with components of my palette in a way that makes sense along with the curved line of the flow

In the slide-show you can find an example of what I’ve done.

ld0ld1ld2ld3

 

I chose to divide the vertical column when the flow pass through the center because in this way every slot has its flow starting and ending in the same area and they can be put in random order and still maintain a pretty consistent flowIn this way during the game, each slot can be randomly loaded as needed from a set of independent slots (like shown above).

 

 

I hope you liked this post :-). The next post I will explain the point system and the overall logic, stay tuned for more devlogs and other articles.

 

I define myself as a creative developer.

Blur effect shader

 

I’d like to share this post-process shader that I wrote to apply a simple blur effect on a video source on Panda3D engine. The related manager class (written in Python) adds more control and customizability to the shaders, but if you want, you could use just the plain GLSL shaders. Follow the link down below and happy blurring! 🙂

Source code

https://gist.github.com/plafone/cf55e40b8738c8c7707c

 

I define myself as a creative developer.

Texture2D Extension

 

Recently I had to work on Unity with Texture2D taken from a camera and for some reasons they came out flipped in strange ways. So, I had the need to rotate or flip the textures and I realized that Unity doesn’t have this function ready to use.

This is Texture2DExtensions (source code). As the name suggest is a little tool made for resizing, cropping, mirroring and flipping Unity’s Texture2D. It uses basics algorithms to iterate through the textures and set the right pixels.

You can use it right away into your projects to manipulate any Texture2D you want 🙂 Keep in mind though that It’s a little heavy computationally speaking so, don’t use it to manipulate in the update cycle.

Source code

https://gist.github.com/plafone/4b853558eeb062bf3ad0

 

I define myself as a creative developer.