Recent Updates Toggle Comment Threads | Keyboard Shortcuts

  • Derek Stobbe 07:39 on January 30, 2014 Permalink | Reply
    Tags: c#, 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 ());
  • Derek Stobbe 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<Light>();
        // 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);
  • Derek Stobbe 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.

  • Derek Stobbe 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
  • Derek Stobbe 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.

  • Derek Stobbe 16:20 on April 23, 2013 Permalink | Reply  

    braindump 0.0.8 

    I just pushed version 0.0.8 of braindump to pypi; nothing fancy, just adding a -f option to output the path to the topic file, because I wanted to be able to do something like cat `braindump -f some-topic` and get a quick overview of the topic without launching an editor.

    When I was concepting braindump, I wanted to create a command line tool that could easily append random thoughts to a file, but was also flexible enough to use another storage system, if desired — a database, for example, or even something like the Twitter API. To implement the -f flag quickly, I committed an atrocity against that design by using an implementation detail specific to the filesystem dumper, but I did it knowingly, as a precursor to another feature that I want to implement: a plugin system that will allow for adding new options or even new commands.

    There are still a few kinks to work out before I start actually writing code, but with a plugin manager, the FSDumper would be able to register filesystem-specific functionality like the -f flag without bloating the dumper contract unnecessarily (a database dumper probably wouldn’t have a meaningful value to return for a “give me your location” command, for example). With that in place, braindump then becomes as flexible as the end user wants it to be, and that sounds like a Pretty Cool Thing to me.

  • Derek Stobbe 17:55 on April 18, 2013 Permalink | Reply  

    Fate Character Bio: Wil of Renn 

    My character concept for a Fate Accelerated Edition game. The setting is based loosely on the Enchanted Forest Chronicles by Patricia C. Wrede.

    As a wizard in the Enchanted Forest, Wil is highly intelligent and well-read, but his magical abilities have always been… underwhelming, contrasting sharply with his desire to gain the acceptance and respect of his peers. Recently, he earned the ire of several other wizards through what they called “ineffectual, bumbling antics” and “behavior unbefitting the title of ‘wizard’,” which lead to his hazing in the form of being stripped of his belongings, melted in soapy lemon water, and having his staff hidden away where he cannot easily retrieve it.

    Humiliated, and without access to his magic (such as it is), Wil has set out to reclaim both his dignity and his possessions, hoping to prove himself capable to his fellow wizards along the way.

    High Concept: Humiliated Hedge Wizard
    Trouble: “I am NOT ‘ineffectual’!”
    Aspect: It’s All Academic — Wil has studied extensively and can recall from a vast store of knowledge at will, but sometimes struggles to apply that knowledge in real-life situations.


    Clever: Good (+3)
    Quick: Fair (+2)
    Flashy: Fair (+2)
    Forceful: Average (+1)
    Sneaky: Average (+1)
    Careful: Mediocre (+0)

    Refresh: 3


    Talk the Talk
    Because I Talk the Talk, I get +2 to cleverly create advantages when in-depth knowledge might be impressive or helpful.

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