Author Archive

Forward Kinematics in AS3

Monday, April 7th, 2008

A Confession

Kinematics in action
I must confess, firstly, that a week ago I didn’t know what forward kinematics were. Everyone seems to be talking about inverse kinematics lately (”ragdoll” physics), with no love at all for her sister forward kinematics. And really, if such a thing may be said, forward kinematics is the hot sister- I’d take her over inverse anyday.

Here’s the difference: Sometimes its desirable to model movement based on a system of interconnected objects. Your body would be such a system (your hip bone’s connected to your thigh bone, your leg bone’s connected to your calf bone, your calf bone’s connected to your foot bone, etcetera). Inverse kinematics deals with all of this starting from your foot and working inward. This would be ideal for, say, modeling you falling down the stairs or off a building- provided that you were unconscious. The motion that your foot produces during the fall is determines the angle and position of your calf, which then determines those things for your thigh.

Now forward kinematics, on the other hand, goes the other way. The reason you were unconscious in the above example is because any movement started from your body (i.e. flailing in panic as you fell off the building) would be forward kinematics- it starts from your body and moves to the end of the system. Forward kinematics is used to model more mundane things like walking. The thigh is rotated, which determines the position of the calf. The calf is rotated, which in turn determines the position of the foot. Thus, the position of the foot is determined by motion originating at the body, not the reverse.

An Example of Forward Kinematics

Okay, so that’s what forward kinematics is. And here is what it looks like (click the image to see).

AS3 Forward Kinematics

See? He really walks!

A Sponsored Link

(can’t say I wasn’t honest…)

I feel that I should also confess that I got the germ of this little engine from this book:

Foundation Actionscript 3.0 Animation: Making Things Move!

It’s by some guy named Keith Peters who apparently knows his way around the VM2. It’s not a ton of classes- two in his version, three in mine. So if you’ve got $25 and about an hour, give it a shot. And if you buy it from the link above, I get two dollars or something.

Greenhouse

Wednesday, April 2nd, 2008

Looks like the Penny Arcade fellas are releasing another digital games distribution system, a la Valve’s Steam. It’s still in beta, with no games, but a very interesting development for the indie game developers out there. PlayGreenhouse.com.

FFilmation

Wednesday, April 2nd, 2008

FFilmation isometric game engine has been released, and it’s one of the most stunning examples of what Flash can do that I’ve seen since Papervision3D. I almost hate to link to it because it will overshadow my own contributions to the Flash scene…

Flex 3 + Game Dev = Awesome

Monday, March 31st, 2008

<Synopsis!>
First of all, a synopsis of this entry so you don’t have to read the whole thing. First, I’m going to reminisce in a slightly condescending tone. Then, I’m going to suddenly switch tacks and turn my reminiscence into a rather awkward metaphor about how Flex rocks. Then I’ll say something like “download Adobe Flex 3 here and try it for game development.” So if that’s enough to convince you, you can stop reading here. If not, read on! There’s another link to download the Flex trial at the bottom of this post.
</Synopsis!>

A few years ago, before my brilliant web career, I lived a very different life. I worked in a small studio in downstate Illinois as a songwriter and producer. This was not quite as awesome as it sounds. Usually it meant dealing with clients who were pretty convinced of their own brilliance, who brought me lyrics scratched on stained and wrinkled napkins. “It goes like this,” they would say, and hum me a series of unrelated notes.

Emo kid

My job was to take this stained napkin and these notes and, through a sort of studio alchemy, synthesize an actual song. I acted as an amplifier for the natural talent of the client. If she thought she might want some drums, I was the drummer. If this called for some keyboard or guitar, then that was my job too. If there was a note a client didn’t like or a harmony that didn’t seem to work, it was my job to suggest a better one. I became an extension of the client- the whole point of my employment being to make each artist sound better than they actually were.

Okay, now let’s make the awkward jump to the other side of this too-obvious metaphor. The hapless client is now the Flash developer. The studio is now the Flash player and development environment. And the producer, the guy who amplifies your strengths and fills in for your weaknesses… that producer is Flex 3.

Yes, it’s an awkward metaphor. I realize this. But it’s very important to me that I evangelize Flex as much as possible, and this particular comparison makes a lot of sense in my head. Actionscript 3 dropped a ton of new functionality in our laps- the Flash Player 9 API is like five times the size of Flash Player 8’s. In many ways, the AS2 expert, the Java developer, and the AS newbie are all in the same boat (to mix metaphors) when it comes to starting AS3. It’s a room full of powerful equipment and there’s no one to ask for help.

Flex Assistance

So that’s why I am evangelizing Flex 3. If you’ve been using the Flash CS3 compiler, you’re going to freak when you start using the Flex 3 compiler. Seriously, it’s that awesome. And Flex itself provides a ridiculous amount of help in the form of auto-completion and code hints. It’s like that producer. You say “I’d like to make a call to that BadGuy class I made three weeks ago.” Flex 3 says, “Awesome! You’ll need to send it the following five parameters, of these five types, in this order.” As soon as you mistype a variable name Flex is there with a friendly reminder: “Ahem. The ScoreKeeper class only accepts Numbers. I suggest you change your approach.” No more thirty-second compiles in Flash only to find that you have errors in your code. It’s instant- Flex checks your syntax and compiles every time you save.

Flex Errors

Okay, I’m getting carried away here. I can’t help it- I’ve only recently started using Flex for game development, and it’s changed the way I code. I know you FlashDevelop and Eclipse folks have had these functions forever, but it’s new to me. I can get twice as much done in half the time, with a third of the frustration. Or something. So if you haven’t tried Flex for your game development, I suggest you give it a whirl. Adobe even gives you a 60-day trial here. Seriously, how can you lose?

Credits
The studio above is The Noisegate, in Pekin IL. It’s a beautiful studio, and Mike Layne (lead engineer) is a great guy. Tell ‘em I sent you.

AS3 Earthquake Class v1.0

Monday, March 24th, 2008

I’ve noticed that there are a lot of small things that can save you time when designing and coding a game. Stuff that wouldn’t take long to code, but if someone’s already done it, why bother?

So in that glorious spirit of apathy, I present to you the Pixelwelders Earthquake class. This is just a simple little class that allows you to create an earthquake (or explosion, or invasion, or whatever) in your game. You just feed it a DisplayObject, the intensity of the quake, and the duration in seconds, and voilá. This is the syntax:

Earthquake.go( displayObject:DisplayObject, intensity:Number, seconds:Number ): void

And this is a two-line example:

import com.pixelwelders.fx.Earthquake;
Earthquake.go( gojira, 10, 1 );

And this is the result. Notice that each time you click, the earthquake is slightly different. Scroll down to download the class.

Download the class (and the above example) here.

AS3 A* Pathfinding Engine (v1.0)

Friday, March 21st, 2008

She ain’t much to look at, but she sure do work. Honestly, I’m not exactly sure how it works. A recursive function is a fierce and fickle mistress.

Pathfinding engine v1.0

Actually, I do know how it works; I was just startled at how fast it came together. There are a lot of great resources on the subject, as well. Here’s the one I used:

A* Tutorial for Beginners

And if you’d like to play around with it, just click the image.

The real problem I have with it is that it’s pretty short-sighted. Units don’t see a wall until they’re right on top of it. Obviously this makes sense for a lot of units- sometimes you don’t know where you’re going until you get there. But I think I’m going to try some smoothing algorithms to remove some waypoints and get those paths a little more natural-looking.

Boxhead

Monday, March 17th, 2008

Boxhead- The Zombie Wars came out today. Very impressive work from Sean Cooper. Go play!

A Flash Horror Story

Monday, March 17th, 2008

A Terrifying Celestial BodySometimes deadlines make you do things… terrible things. Things that you wouldn’t want associated with your name because they could single-handedly ruin your career. Systems and classes that you hope against hope will never ever have a problem or need an update. But the whole time, something in you is telling you this is wrong. This will come back to haunt me. Sometimes you’re lucky. But usually you’re not, and it does come back to haunt you- with a vengeance.

I want to tell you a story about a man- a desperate man. We’ll call him Ted. Ted was a graphic designer who was just getting into Flash, and so he took a freelance job with a local Flash development house to put his new skills to use. This company tasked him with creating a fun little app that allowed the user to customize a car image. The user, they said, should be able to add logos, spoilers, “dubs,” etc. and then download his/her fantastic creation as a wallpaper. In fact, they continued, we’ve already finished the layout and the car images- here’s an FLA and a zip of all 170 possible combinations.

At this point, many developers are already putting this app together in their own minds. Twenty lines of code, maybe a splash of XML, a big image directory- call it a day. That is, in fact, what the development company expected. However, the days turned to weeks and Ted had not turned in his project. Phone calls became less frequent and more harried. Finally, hours before deadline, Ted emailed a link to the project. It loaded a bit more slowly than anticipated, but it was assumed that it was just because of the size of the graphics. Which, as we were to find, it was.

However, the client soon decided that a small change was needed. Because of the rather lengthy turnaround time with Ted (who was now slogging through another project), the development company gave it to an in-house guy this time, who was confident that he could make the change in a half hour. How complicated could an app like that possibly be? He downloaded Ted’s source from the development server and opened it… and that part of his soul that every human is born with, that sings because the Earth is beautiful and its people are good- that part died within him.

A Flash timeline nightmare

The source files bore the unmistakable mark of a madman, drunk with desperation. The project contained one hundred seventy keyframes, each containing one of the car images. To view one image, in other words, required downloading its 169 siblings as well. Furthermore, each keyframe held five buttons for adding the various options to the car. Five completely new instances per keyframe, each with a unique instance name (redSpoiler155_btn, redSpoiler156_btn, etc.). Furthermore, each of the five buttons had a variant of the following code attached directly to it:

on(release){gotoAndStop(51)}

170 x 5 = 850 identical lines of code. In 170 unlabeled keyframes. Attached to 850 separate and unique button instances. In a project with 170 wallpaper-sized images that, when compiled, produced a 20MB SWF. The reason neither the development house or the client noticed the download time was because they were operating on A) industrial-strength Internet connections and B) the assumption that the freelancer hired was not a complete sociopath.

To be fair, we all know what happened. The guy had gained a couple skills and went with what he knew, rather than doing a ten-minute Google search, without ever thinking seriously, there has to be a better way. Nonetheless, the second his “techniques” came to light, the development house called him to request that he invoice them immediately and go work for someone else.

They say on certain nights, when the moon is full, you can still hear the feverish and half-insane clicking of a man attaching code to onstage objects.

Fancy Pants

Saturday, March 15th, 2008

Have you played Fancy Pants Adventure- World 2 yet? If not, I urge you to go experience the best platformer-type offspring that Flash has yet produced. Then you should probably drop by and say hello to its author.

Holodeck

Saturday, March 15th, 2008

Your Ultimate Game Chair is out of date. If you’ve got £15,000 lying around, maybe you should pick up a Holodeck.