Recent Updates Toggle Comment Threads | Keyboard Shortcuts

  • problematic 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

    [youtube https://www.youtube.com/watch?v=_UkUl4fFX-A /]

    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
                StartCoroutine("ToggleBulletTime");
            }
        }
    
        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!

    [youtube http://www.youtube.com/?v=uPLahFRlmVA&w=625

    Here’s the code used in the video:

    using UnityEngine;
    using System.Collections;
    
    [RequireComponent(typeof(Light))]
    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);
        }
    }
    
     
  • 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 problematic.io domain because I was tired of wrestling with an EC2-based WordPress install, and I was irritated that wordpress.com 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 iamproblematic.com now redirects to problematic.io. 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 djstobbe@gmail.com 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.

        Sincerely,

        Chris

        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 t.name 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.

     
  • problematic 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.

     
  • problematic 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.

    Approaches

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

    Refresh: 3

    Stunts

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

     
  • problematic 01:10 on December 5, 2012 Permalink | Reply
    Tags: , , ,   

    Holy cow, only 9 months late! Part 1.5 of the Symfony2 tutorial series I started a while back:

    [youtube http://www.youtube.com/watch?v=oLB9FvxI7kA&w=625

     
    • Steve Jamm 09:01 on May 9, 2013 Permalink | Reply

      I am waiting for the next part =)

    • Dennis 16:58 on April 17, 2013 Permalink | Reply

      What are you using for the command line tool?
      Thanks

    • o martins 04:24 on March 5, 2013 Permalink | Reply

      Thanx man!
      Finally got me started on Symfony.
      “…I can promise that it won’t be nine months before the next episode.” — Well…? Three months since you posted this one… ;)
      I’d love it if you made a tutorial on security.

    • KRTCS 15:48 on February 9, 2013 Permalink | Reply

      I stumbled upon your site while researching Symfony2 as a framework to use for a PHP project. I must say, Good stuff. I am glad to hear you will be posting more. I do know how life comes by and changes your plans! I will be watching your blog for more sf2 stuff! -Ken

    • Domingo 07:49 on January 17, 2013 Permalink | Reply

      Hello! I was searching on stackoverflow in a way to authenticate my users after registration and I found your solution (http://stackoverflow.com/questions/5886713/automatic-post-registration-user-authentication). But for some reason in Symfony 2.1 this does not work, any ideas? Thanks for any help, im stuck here for about one week!

    • Marcus 03:13 on December 7, 2012 Permalink | Reply

      Much appreciated video :)

  • problematic 13:04 on May 3, 2012 Permalink | Reply
    Tags: amazon, ec2, heroku   

    Why I like Heroku 

    That was me, like ten days ago. I recently started trying to broaden my Twitter horizons to include more python-related stuff, since the vast majority of my feed was either PHP/Symfony2-related, or retweets of funny cat pics. So, I added the first Python user that came to mind, @kennethreitz. As it turns out, he’s the Python Overlord over at Heroku, and tweets about it occasionally, so I decided to check it out.

    Color me impressed. As I mentioned in my tweet, I did the quickstart and by the time I was finished with it, I had already decided to make the switch. There are a few features that I really enjoy:

    1. Foreman, which is a command-line tool for testing your apps in the same environment that Heroku will use
    2. Ease of deployment. git push heroku master and you’re done. Seriously. They take care of the rest
    3. Seamless scaling. With Amazon EC2, I had to create a disk image, spin up a new EC2 instance, set up a load balancer… what a pain. With Heroku, you can have as many (or as few) processes running as you want with one console command, and load-balancing will happen automatically
    4. Worker dynos. It’s really easy to spin up non-web-facing processes to manage queues and what have you
    5. Free tier per app. Each app you create gets 750 free dyno-hours per month: more than enough for development and testing and low-scale production work
    6. Suggestions for deployment. You can find tons of tutorials and guides for setting up development environments, but I’ve found very few that talk about creating a production-ready application. As part of the quickstart guide, Heroku actually goes into how to set up and use something more than the built-in development servers (gunicorn for Python, for instance)

    Top all that off with easy-to-use add-ons (easy as in “click a button and it’s ready” easy), and I see no reason to ever go back to managing an Amazon EC2 instance again. There’s no “official PHP support” right now, but Heroku and foreman make it easy enough to develop deploy a Ruby or Python app that I no longer stress about setting up environments for them. A big win all around.

     
    • Keth 06:42 on June 22, 2012 Permalink | Reply

      Hello,

      this sounds very interesting. But what is “low-scale production work” for you? A community website with 100 daily visiting users? :D

  • problematic 23:57 on April 28, 2012 Permalink | Reply
    Tags: django, django-admin,   

    Django-admin and single-item tuples 

    Today I learned something about Python that I did not know before: single-item tuples must have a trailing comma.

    I mentioned before that certain aspects of Django leave a bad taste in my mouth, and that I was looking to other solutions as I move my language of choice for web development from PHP to Python. However, in the end I really couldn’t ignore my own advice, and I’ve been getting to know Django a little better, mostly for all the batteries included (user authentication, for example). I kinda like it. The automatic admin generator, for instance, is really nifty; at work, it lets to get the non-programmers in the other room up and running before the project is really anything more than a handful of classes.

    The admin site is dynamically generated from your models, and has a concept called fieldsets: logical groupings of fields in the admin form. From the docs, here’s an example:

    class FlatPageAdmin(admin.ModelAdmin):
        fieldsets = (
            (None, {
                'fields': ('url', 'title', 'content', 'sites')
            }),
            ('Advanced options', {
                'classes': ('collapse',),
                'fields': ('enable_comments', 'registration_required', 'template_name')
            }),
        )
    

    Basically, a tuple of tuples containing the fields and other options. Anyway, while I was creating my admin class, I kept getting a weird error:

    ImproperlyConfigured at /admin/foo/bar/add/
    'BarAdmin.fieldsets[2][1]['fields']' refers to field 'x' that is missing from the form.
    

    Where the name of the field in question starts with the letter ‘x’. I was initially frustrated because the exception message isn’t very helpful, but it turns out, this isn’t so much an issue with Django as it is a gotcha in the way tuples work. My admin class contained a fieldset with only a single field, like so:

    fieldsets = (
        ('Advanced', {
            'fields': ('xylophone')
        }),
    )
    

    Okay, ‘xylophone’ is a little contrived, but my example error from earlier started with an ‘x’. Shoot me. Anyway, after RTFM, it makes perfect sense. Since my single-item tuple lacked a trailing semicolon, it wasn’t a tuple at all, but an expression. And the expression ('xylophone') returns what, class? The string xylophone. Very good! Then the interpreter was trying to iterate over a string, only there is no field that matches the first item returned: x. Hence, an error.

    This is why I find actual fieldwork with a new language, framework or library to be the best way to learn it, over reading the documentation or sourcecode or anything else. Now that I’ve learned that little tidbit of information, it’s mine and I’m unlikely to make that mistake again (or if I do, I’ll recognize it instantly when I see it). No amount of documentation-reading could possibly make it stick in my head like that.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel