June 2009 Archives

I've been doing some more work with my Steering Behaviour library. It was originally tightly integrated to box2d and its data types. I've been working to make it more modular and not dependant on anything other then the flash library.

This has been going well, although I was running into a particular problem with the Wander behaviour, where the objects using it would just circle around clockwise. This was obviously not the correct behaviour!

Going over the code, I realized that i'd set a default wander position as Point(0, 10). Do you see my mistake? I was making an assumption that the local angle of 0 was aligned with the positive Y axis. Not so, it points to the positive X axis! What I should have had, and now do, is Point(10,0).

It took me longer then it should have to fix this because I didn't have a visualization of what the Wander() function was returning. As soon as I visually added that info to the screen, it became obvious what was going wrong.

So, two points to take home today! One - remember which axis is aligned with 0 rad/degrees! Two - if you can plot your data to the screen for debugging, do so!

Making it to 1.0

| 0 Comments | 0 TrackBacks

I just wanted to note the successful attainment of the coveted "One Point Oh" release for RealmSpeak!

RealmSpeak is a computer client and server for the game Magic Realm. This game was released in 1978! I actually own a copy, although I've never played it with anyone else. It is, to say the least, a tad complex. I've been using RealmSpeak to learn the game, and while it is slow going, it is still fun.

I think that the effort Robin has put into this program over the years, simply for the love of the game, is something to be noted.

Congratulations in helping keep this game alive, and its community!

Above average difficulty

| 0 Comments | 0 TrackBacks

In one of the projects I'm working on we have a top-down view of the play-field. The actors on the field turn quite quickly, and sometimes twist from left to right in a non-visually pleasing way. My first thought was, well, I'll simply average the direction's over X number of frames. My next thought was "how do you average a heading/angle?".

Because the heading 0 and 360 are the same, you get weirdness if you do a naive averaging formula. For example, with a list of headings like so [360, 360, 0, 0], you'd end up with an average heading of 180 degrees. Which, you know, is wrong.

So, off to the trusty internet to find an answer! The first thing I read had an interesting conversation about how meteorologists would be the ones to consult, as they have to do this all the time. For averaging wind direction. So, while that was illuminating, I didn't feel very confident in any of the actual answers presented there.

My next hit was at StackOverflow, which, if I'd thought about it a bit more, should have been my first port of call. Luckily, Google indexes it, and I found this question and answer. Simple and works great!

So, that's what I learned today! Who says you can't learning anything useful from the internet!