PO Box 312
Jefferson, OR 97352
503.383.9622
New Family Blog
August 2nd, 2010 by Shawn

Well as usual, when it comes to me and blogs, this one has been severely neglected. It seems like I never have anything to write about, and when I have something to write about I can’t find the time to sit down and write about it! This, however, has not been the case for my wife, who has been busy at work with the new family blog. She is shifting her focus from her Facebook obsession to managing a great little family picture blog over at http://lehnerfamilyblog.com. I am really proud of her, she has really been putting a lot of work into getting up and going, even to the point of learning some basic coding to fix her own layout issues!

I do plan on getting back into blogging as soon as I can. It has just been a whirl wind of different projects at work the last few months. From trying to crank out games, updates, software fixes; this wouldn’t be too bad with a larger team, but our team is small and that means everyone is wearing multiple hats.


Veggie Samurai HD Released!
June 21st, 2010 by Shawn

For those of you who don’t already know, I work as a game programmer at “QuantumSquid Interactive” for my day job. We are a small, independent game company based out of the Portland, OR area. We have been working full time on games for almost 2 years now and have released games on Xbox 360 Indie Games, the iPhone, and now the iPad. While we are a very small company, we have a passion about games that we must continually fight to ensure we do not bite off more than we can chew. At the writing of this article we are actively working on updates for 3 games, we have 2 new games underway, and plans for a new game in the works.

Veggie Samurai HD, our first iPad game, hit the app store on Saturday. While we are all very excited about the launch of Veggie Samurai, we are also perfectionists, and as such already have our first update nearly complete and hope to submit today! We also have a detailed outline for 2 more future updates which should find their way into the app store in the coming months.

So if you have an iPad go give Veggie Samurai HD a try!


Dynamic scene saving in Unity3D
February 20th, 2010 by Shawn

Since we are working on a live action RPG and really want to emulate as much of the feel as you would get playing inside an MMO world like EQ or WoW it is obvious we are going to need an easy and flexible way to save state data for each object in each scene. The first thing I needed to figure out was when these saves should happen. We know we need to save the states for all objects anytime we are going to be leaving the scene and these objects are going to be unloaded; this tells us we basically need to save on scene transitions and when the player closes the game.

The next thing we need is a unique way to identify each object in the scene that will be persistent between each load. The initial thought I had was to use a GUID that is generator in the editor when an object is created but it appears the .NET Guid is not implemented correctly in the iPhone version of Unity. This meant that I needed to find a quick and easy way to generate a unique id for each object, which led me to the method below.

    private static ulong m_next_safe_index = 1;
    /// <summary>
    /// Creates a unique hash ID based on a seed string and computed using current
    /// time and other random aspects.
    /// </summary>
    /// <param name="seed">What you would like to seed the random name with</param>
    /// <returns></returns>
    public static string CreateUniqueID(string seed)
    {
        byte[] plainText, rawHash;
        using(MemoryStream pbs = new MemoryStream())
        {
            using(BinaryWriter bw = new BinaryWriter(pbs))
            {
                bw.Write(seed);
                bw.Write(System.DateTime.Now.Ticks);
                bw.Write(Random.value);
                bw.Write(m_next_safe_index++);
                bw.Write(seed);
            }

            plainText = pbs.ToArray();
        }

        rawHash = new MD5CryptoServiceProvider().ComputeHash(plainText);
        return System.Convert.ToBase64String(rawHash).Replace('+', '-').Replace('/', '_');
    }

The first thing to note about the above method is that it will NOT create a truly unique id each time; but the probability of it generating the same id during the life of this project is very slim. It basically uses the current ticks of the time component to make sure the value is unique between invocations, in the case where we call it multiple times in the same frame (where the ticks could be the same) we also use an incrementing variable. The seed wrapper is just an added layer of insurance to prevent objects of different types from sharing the same id space.

Now that we have a unique id to work with we can figure out how to invoke our save. In Unity this is very simple, since all of the objects that need to have their states saved are scripts we can use the GameObject.FindObjectsOfType() method to track down all our savable scripts. This method will take a base class or interface and return all objects which are assignable from that class.

The next step is to create our base savable object structure. This structure will probably be tailored to whatever type of game you are creating, in my case I created a very flexible base class which I could easily extend for more complicated objects. You can see the base class I used below:

using System.IO;
using UnityEngine;

public abstract class SavableBehaviour : MonoBehaviour
{
    public string UniqueID = SaveManager.CreateUniqueID("SN");

    public abstract void SaveState(BinaryWriter bw);
    public abstract void ReadState(BinaryReader br, float elapsed);

    protected virtual void OnDrawGizmosSelected()
    {
        Object[] savables = FindObjectsOfType(typeof(SavableBehaviour));
        foreach (SavableBehaviour sb in savables)
        {
            if (sb == this) continue;
            if (sb.UniqueID == this.UniqueID)
            {
                UniqueID = SaveManager.CreateUniqueID("SN");
                break;
            }
        }
    }
}

Notice that the above class extends the Unity MonoBehaviour class. The reason I wanted to do this instead of using an interface is because of the method I use for finding my savable objects. It will force me to only use MonoBehaviour classes which can be returned by the FindObjectsOfType() method I am using. Also note that the ReadState() method receives an elapsed parameter. This is so that each object can simulate the amount of time which has passed since the scene was saved, it is very useful for managing rare boss spawns.

There are still a lot of kinks to work out with my saving system, but for 2 days worth of work I think it is coming together very nicely. One issue that has driven me crazy is the need to create a new unique id when you duplicate on of these objects in the editor. Since we use a public field to store our id so it gets auto-serialized with the scene it is also copied when we duplicate the object. I am looking for a good solution for this, the temporary solution is to hack up the OnDrawGizmosSelected() so that it changes the id of the newly duplicated object. It seems to be working fine for right now but it makes me anxious having code like this that is a bit unpredictable.


Dropbox
February 12th, 2010 by Shawn

I have been using Dropbox for a few months now and I am still finding new features which just blow me away. The most recent of those features being the fact that it stores every version of your files for the last 30 days which you can easily go online and download if you screw something up.

For those of you who don’t already know, Dropbox is an application which runs in the background and syncs all files saved and/or changed in a specific to your account online. You can install it on multiple computers and it will automatically sync your files between your computers; you can also access any of your synced files online via their website which is really great if you are on the go. Don’t hesitate to give it a try! They offer a free account option which is full featured and provides 2GB of storage space, there really is no losing with that deal!

Here is a quick break down of the features I have found and LOVE!

  • Automatic file synchronization between computers and operating systems.
  • Mobile device support including iPhone
  • Stores a backup of your files online in-case hard-drive failure
  • Stores all versions of your files for the last 30 days
  • Ability to send links to your files, works like having your own file hosting

Pathfinding and AI
February 10th, 2010 by Shawn

I just finished up the first pass of my dynamic path finding system for our upcoming 3D RPG game and the results are very promising! It uses the physics system to map the 3D environment and store it with height data as a 2D A* grid which it uses for the characters to navigate. The characters then access this navigation information to guide them around the scene. The best part about this method is now the characters do not need to have colliders taking up our valuable performance; they will have passive triggers so that I can use a ray cast to select them but these will not eat up much CPU performance.

You can see a rough draft shot of the system to the left.

I have been working on the AI and have been using an AI settings module which is defined in the editor on the spawn node and is passed to the spawned creature at run time. This module contains information on how the creature should behave, wander, etc… the test running right now is using the wandering behavior and is working GREAT! I am very excited about the results and look forward to the rest of the AI systems.


Pathfinding
February 8th, 2010 by Shawn

I am working on figuring out a very non performance intensive method to simulate environment collision and path-finding in 3D space for an upcoming iPhone title I am part of. I have been wrestling with a few issues; the main problem is that standard character colliders are too expensive to use on the iPhone for each enemy you will be fighting. The cost of these colliders and the fact that we really don’t need to know real time about what they are colliding with makes it pointless to be using the standard character controller provided with Unity.

The first solution I am investigating is the idea of creating a dynamic 2D A* path-finding grid for the area around the character; since each character is limited to a “home zone” to prevent a large number of draw calls there doesn’t need to be any collision data saved for an area unless there are characters there to utilize it. My plans are to generate this data in the editor and save it into binary files which will be loaded with the level and parsed into memory to be used later. This information should contain information about the state of each node, including whether it is blocked and its elevation. When a character spawns it will be snapped to the nearest node and elevation, then any movement it makes from that point forward will be snapped to the A* grid and use the collision data we have generated ahead of time to figure out its best path, this should provide a semi-realistic movement behavior with very little performance cost.

I have not performed any tests at this point and I will do a follow up post once I have results. I really hope this first solution works; it seems like it could really help improve the amount of characters we could have on screen at a given time.


Finding motivation
February 1st, 2010 by Shawn

I have been having some trouble as of late to get motivated about the personal projects I would like to work on. It seems that every time I open up a project I find myself just looking at the screen trying to figure out where I want to begin. For freelance projects it is easy… there is always some type of deadline that forces you to push forward. Even though I get very excited thinking about the projects and applications I would like to create, and that I can honestly see there is a market for them, I just really find it hard to force myself to push through to completion.

I would like to work on some of them tomorrow night if I have time… lets hope I have the motivation this time!


Electronic troubles
January 31st, 2010 by Shawn

Well our dryer has been having issues for the past few days… anytime you are trying to use it you have to hold the button down for a good 10-20 seconds for it to stay running. During this time it makes some pretty wicked clicking sounds, so I decided it was time to take it apart and see what I could find.

Once I finally got the control panel apart it wasn’t long before I spotted the problem. The electric control board had a resistor that was dead, the area the resistor used to be sitting was charred and the resistor itself was sitting at an odd angle. When I flipped over the board I noticed that the pathways leading from the resistor were a little black but nothing major. Based on this newly acquired information I decided it was time for me to try my hand at soldering!

I am heading into town a little later to pickup a soldering iron, some solder, and a new resistor from RadioShack… I am really looking forward to giving this a try, even though I distinctly remember having very unsteady hands when I have tried this in the past =). I will post some pictures of the before and after results when I finish the project… wish me luck!


Setting up my blog
January 30th, 2010 by Shawn

I am working on setting up my blog and it is kind of a learning experience =)! I am trying to figure out how to configure everything in Wordpress and at the same time learning how to create a custom theme from scratch. I am working on the styling for the blog page at the moment, so pardon any hideous formatting you may see over the next few minutes.