Recent Updates Toggle Comment Threads | Keyboard Shortcuts

  • problematic 14:01 on August 21, 2014 Permalink | Reply  

    Watch the Unity keynote 

    The Unite 2014 keynote was yesterday. There’s lots of exciting stuff coming for Unity (I’ll cover that in another post), but you can watch for yourself:

    Some highlights

    • IL2CPP turns your C# bytecode into C++ code and compiles it, and is as fast as native C++
    • The new UI slated for Unity 4.6 is in open beta, and will be an open-source component hosted on Bitbucket
    • Unity 5’s GI (Global Illumination) and physically-based shaders look very impressive
  • problematic 16:43 on August 19, 2014 Permalink | Reply
    Tags: game-assets, indie, support   

    Go Support Kenney Land 

    Are you familiar with Kenney? If you check out his Open Game Art profile, you’ll see that he does awesome work, and makes a lot of it CC0/public domain, so that anyone can use it for their projects.

    Well, he just started an IndieGoGo campaign to fund a space in the Netherlands called “Kenney Land,” for game developers to work, learn, and play. The campaign closes on 18 October, so you should check it out while you have the chance! If that idea alone is not reason enough to throw your money at him, backers at the $20+ level get a brand new 2D asset pack, including reworks and expansions for some of his previous work, a 2100+ asset “Roguelike pack,” and a bunch of audio clips and tracks.

    What are you waiting for? Go!

  • problematic 20:27 on August 16, 2014 Permalink | Reply
    Tags: , research,   

    Anatomy of a Unity script 

    Here’s an example of the default script that Unity will create when you ask for a new C# script:

    Most of this makes sense, but I’ve found myself wondering, “why would they include System.Collections, but not System.Collections.Generic?” There aren’t very many cases where I’d rather use an array than a generic List. The other default import, UnityEngine, makes sense because it provides access to the Unity API, but I couldn’t figure out System.Collections.

    I discovered the answer while reading through Catlike Coding‘s Unity tutorials (specifically, the tutorial on making fractals):

    Move the two child creation lines to a new method named CreateChildren. This method needs to have IEnumerator as a return type, which exists in the System.Collections namespace. That’s why Unity includes it in their default script template and why I included it in the beginning as well.

    CreateChildren in the script referenced is a coroutine[ref]See the Unity manual entry on Coroutines for more information[/ref], which provides our answer: Unity coroutines must have a return type of IEnumerator, which is found in the System.Collections namespace. As a core framework feature, it makes sense that the Unity team would choose to include this by default in the new scripts created by the editor.

  • problematic 03:16 on August 11, 2014 Permalink | Reply
    Tags: , ,   

    Unity3D mouse follow script 

    I wrote this script to have a GameObject follow the mouse cursor, converting mouse position to whatever coordinate space you need. I use it with viewport space to display grid coordinates next to the cursor with a GUIText component.

  • problematic 16:29 on July 26, 2014 Permalink | Reply
    Tags: , , protip,   

    Preserving C# event delegates on code change in Unity3D 

    While tooling around with Unity, C#’s event delegates have quickly become a standard part of my utility belt. They’re a great way to separate concerns and drive events in a typesafe way (as opposed to Unity’s built-in GameObject#SendMessage, which uses string method names), but I quickly noticed something frustrating: when I would make a code change while in play mode, all of my registered events would be lost, and I would have to stop and start the game to bring them back. It might seem minor, but I’m all about removing inconveniences during the development process, so after trying a few different things without success, I put the question out on Twitter. Big thanks to @catlikecoding for a quick answer: add your event handlers to the delegate in OnEnable instead of OnStart or OnAwake.

    One thing to be aware of is that OnEnable can be called numerous times during the lifecycle of your game: when you start, when your code changes, and significantly, if you disable and re-enable a component. This last one can be the source of subtle bugs where your event handler will be called multiple times per event, so you should be careful to tear down events in OnDisable as well. Here’s some example code:

  • problematic 07:39 on January 30, 2014 Permalink | Reply
    Tags: , coroutine, lerp, linear interpolation, , ,   

    Lerping the Matrix: Implementing Bullet Time in Unity 

    In this video, I talk about coroutines, and the proper use of Mathf.Lerp

    And the code:

    using UnityEngine;
    using System.Collections;
    public class BulletTime : MonoBehaviour {
        public float minTimeScale = .5f;
        public float transitionTime = 1.0f;
        bool isBulletTime = false;
        // Use this for initialization
        void Start () {
        // Update is called once per frame
        void Update () {
            if (Input.GetButtonDown ("Ability")) {
                StopCoroutine("ToggleBulletTime");  // make sure we're not trying to speed up and slow down at the same time
        IEnumerator ToggleBulletTime () {
            isBulletTime = !isBulletTime;
            float start = Time.timeScale;
            float target = isBulletTime ? minTimeScale : 1.0f;
            float lastTick = Time.realtimeSinceStartup;  // we need to keep our own deltaTime, since Time.deltaTime is affected by changes to Time.timeScale
            float t = 0.0f;
            while (t <= 1.0f) {
                t += (Time.realtimeSinceStartup - lastTick) * (1.0f / transitionTime);
                t += Time.deltaTime * (1.0f / transitionTime);
                lastTick = Time.realtimeSinceStartup;
                Time.timeScale = Mathf.Lerp (start, target, t);  // we need to use a constant start, not our current value, or we run about twice as fast   as we're intending
                Time.fixedDeltaTime = 0.02f * Time.timeScale;
                yield return null;
        void OnGUI () {
            GUI.Box (new Rect(Screen.width - 150, Screen.height - 50, 75, 25), Time.timeScale.ToString ());
  • problematic 10:52 on January 28, 2014 Permalink | Reply
    Tags: , ,   

    Creating a flashlight GameObject in Unity3D 

    I’ve been playing around with Unity 3D lately, and I put together a short tutorial video about some of what I’ve learned. Enjoy!

    Here’s the code used in the video:

    using UnityEngine;
    using System.Collections;
    public class Flashlight : MonoBehaviour {
        public GameObject source;
        public AudioClip toggleSound;
        Light _light;
        // Use this for initialization
        void Start () {
            _light = GetComponent&lt;Light&gt;();
        // Update is called once per frame
        void Update () {
            if(Input.GetButtonDown ("Flashlight")) {
                _light.enabled = !_light.enabled;
                AudioSource.PlayClipAtPoint(toggleSound, transform.position);
            transform.Rotate(source.transform.rotation.eulerAngles - transform.rotation.eulerAngles);
  • problematic 13:12 on October 16, 2013 Permalink | Reply  

    Meet the new boss (same as the old boss) 

    So, I just did something that you really shouldn’t do on the internet: I revised history.

    That is to say, I originally created the domain because I was tired of wrestling with an EC2-based WordPress install, and I was irritated that blogs don’t give you the kind of control I was looking for. So, I baked up a new blog with Jekyll… and promptly stopped using it. It wasn’t until I read Kenneth Reitz’s post “Why I Left Medium” that I realized why: my code-brain and my writing-brain don’t play well together. I was feeling productive because I was tweaking layouts, instead of producing content.

    I followed Kenneth’s lead, fired up a WordPress install on PagodaBox (Heroku for PHP, essentially), and… had two WordPress blogs. So, I’m merging them: all posts have been migrated, and now redirects to The distinction between domains is enough for me to justify the break from code-only posts that I was looking for, without having to manage two separate codebases, and without losing two years of post history.

    Hopefully the transition will be a smooth one; you can ping me in the comments or at if you notice any problems.

    • Andrzej Ośmiałowski 17:28 on December 28, 2013 Permalink | Reply

      Derek, never say never. I migrated to Jekyll few months ago because I was tired of WP. Recently I’ve re-migrated to WP because I was tired of Jekyll :)

      • Christopher Esplin 13:00 on January 19, 2014 Permalink | Reply

        Greetings Derek,

        Your blogging consistency is lousy!

        I switched to Silvrback recently, and I’ve been happy with it. Just saying.



        P.S. It’s pointless to be subscribed to your blog if you never post anything.

  • problematic 15:15 on October 15, 2013 Permalink | Reply  

    Angular Arghlist 

    When I’m learning a new language/framework/whatever, I keep an “arghfile” of gotchas (sticking points, not necessarily bugs) that caught me while developing so that I can document and/or fix them later. Here are a few from my time learning AngularJS:

    • using repeated variables on the repeated element with ng-repeat doesn’t work: <li ng-repeat="file in files" title="{{ file.title }}"></li> doesn’t work (I think this has been fixed in a subsequent release)
    • requiring a parent controller doesn’t work out-of-box if the parent directive loads a template file
    • ng-keydown only works with 1.1.5+ (documentation has been versioned since then)
    • attaching events to child elements from parent directive (may not be a good idea anyway)
    • directive element can’t be self-closing if you use more than one in a row
    • transcluded content is a sibling of its container
    • Promise then doesn’t resolve until $scope.$apply
    • ‘foo’ is the name of a provider’s injected service. ‘fooProvider’ is how you get the configuration object
    • t.value as for t in account_types for select with an object as a model
  • problematic 12:12 on July 3, 2013 Permalink | Reply  

    Roll for Shoes 

    Last night, I was introduced to Roll for Shoes. It was amazing. It’s a microsystem (seriously, you can find the rules if you follow the link and they’re seven lines long) where you start out with a single skill, Do Anything rank 1, roll a number of d6s equal to your skill rank, and gain new skills when all your dice come up sixes or experience when you fail a roll. New skills you gain have to be a subset of the skill that you leveled up in, and have to be related to what you were doing when you rolled, so you end up with weirdly specific skill chains like Do Anything 1 > Looking for Things 2 > Looking for Things in the Couch Cushions 3.

    Since the rules are so simple, it’s easy to get a pickup game going — just throw some dice at someone, shout “Protect yourself, squire!” and you’re off. Don’t worry about waiting for a “proper” group; because you gain XP for failures and you can convert XP into advancement dice, latecomers will rapidly gain new skills to match the rest of the group. In the strictest sense, you don’t even need a GM, since anyone can roll to oppose and narrate failure (I found that letting players narrate their own success was way more interesting than doing it for them), and players bickering and fighting amongst each other drives some really interesting narratives and skill developments.

    Some general advice: don’t worry too much about lawyering the rules. They’re meant to be whacky, not mechanically foolproof. As long as you keep pressing for more and more specific skills, you’ll encourage interesting and funny situations. In practice, we only made it to rank 3 in any skill because of the specificity requirements and the diminishing odds of rolling all sixes, but it works out somehow because it encourages more experimentation with different skills instead of trying to be a one-trick pony with loads of dice.

    All in all, I enjoyed Roll for Shoes because it’s so easy to get started, and because its core mechanic is simple and works well. There was no need for more crunch because we weren’t trying to simulate combat, we were trying to have lots of silly fun. You can read a micro-review of the system from another player on the RPG Stack Exchange, including a link to an example of play, but really you should just try playing the game for a few minutes.

Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc