Jetpack Physics Test
July 16th, 2009 - filed under Tech DemosFinally it’s time to show some progress with a new tech demo. This demonstrates the integration of physics into the Jetpack game engine, along with some live-cached graphical effects and Thing grouping (the moving platform). Note this is just a test of the physics engine and does not reflect what the final game will look like. Please report any problems you experience, and if you like the progress, please digg this post!
Earlier in the project I put some time into writing my own physics engine, but I decided to try a 3rd party library for physics and I’ve been very happy with the result. I am reluctant to use 3rd party code because when I’ve tried in the past I spend more time working around limitations, bugs, and poor documentation, than if I had simply written it myself. But in this case, using the 3rd party physics engine box2dflash has turned out to be excellent. The API was much better than I expected, the docs have some quirks but are substantial, and the community is large. The result is way more functionality than I would have ever achieved, with a lot less work on my end.
While doing some minor optimization checks by selectively disabling certain features, I noticed a significant slowdown was being caused by alpha changes (translucency). Strangely, if the graphic contains translucency but you don’t alter the alpha, there is no slowdown. So I implemented a smart per-object cacheing system – in this case, alpha is applied and the graphic is drawn to a cache, and future changes in alpha trigger a cache refresh. This is useful for any property that doesn’t change too often, like a rotated object at rest – render the rotated version to the cache, then all future frames will render the cache without rotation. Using this technique and the box2dflash physics engine, on a typical machine I’m able to get 100 balls interacting (each with 2 translucent graphical objects), plus all the level blocks, and maintain an average 40fps. Using Flash as a platform will not be a problem.
The next tech demo will be a control test – binding user input to commands, passing those commands to a Thing’s state machine, applying forces/motion based on the current states, and activating graphical representations of those states. In other words, running around. To be updated on future Jetpack developments, please register on JetpackHQ!
Update
This is a little jerky at times mainly because the code that lowers the frame rate under high load isn’t currently functional. It’s trying to hog the processor and the browser isn’t having it. This will be fixed in a later release.


July 16th, 2009 at 9:55 am
Wow, marble worm levels with this kind of balls is going to be hard…
July 16th, 2009 at 10:03 am
eheh thats cool! maybe it slows down a little bit sometimes;
i am sure in the final game you will be looking on the fps that everybody
can enjoy playing jetpack2!
July 16th, 2009 at 10:09 am
Looking really nice! I noticed one error (which I guess wouldn’t show up in the game):
1: Turn gravity off
2: click collapse
3: turn gravity back on … nothing moves!
4: release some balls, and once the balls touch a wall, everything starts to collapse!
Well its kind of a nice chain-reaction effect. I guess this has something to do with you optimisations. I suggest adding a trigger on gravity change which forces everything to be re-evaluated.
Keep up the good work!
Daniel.
July 16th, 2009 at 10:12 am
Nice work! The physics seem quite realistic. The difference in the bounce or ricochet of the glass ball vs the steel ball is quite impressive. I also noticed the animated reflection in the steel balls as they role, very nice. I know its probably a while from production, but i’m excited for it regardless! haha
July 16th, 2009 at 11:24 am
This is amazing!
Will you be adding new “monsters”?
July 16th, 2009 at 11:50 am
Very nice. The only problems I see are the ones Daniel mentioned (Happens in Elebits, though, too, try it! Objects that are at rest won’t be affected by gravity until something touches them) and the fact that the moving platform will happily force two objects to move inside each other, though I doubt that will effect gameplay in the finished product.
July 16th, 2009 at 12:55 pm
Ahh yes the gravity issue’s easily fixable.
There also seems to be a problem with the total Thing count going negative the more you click Reset. Strange.
I hope this demo will help get the word out that Jetpack 2 is coming. I had a mailing list of a few thousand people, but apparently 10 year old email addresses aren’t worth much.
July 16th, 2009 at 2:13 pm
Well for what it’s worth, I’m still around. Just…not with Juno anymore. XD Ah, the days of Jetpack and Squarez Deluxe… It’s gonna be awesome reliving those days in a this-generation sort of way! With new features and enemies and all that, too! I’ve said this before, but I’m excited!
Also, the physics seem pretty good. I think that anti-gravity glitch should become a feature, myself. Have something like an enemy or a ball roll over a gravity switch and start the level tumblin’…
I have a pretty old computer, so when a whole bunch of moving stuff starts piling up on the screen, I tend to get a lot of lag. I kind of assume most people with big, buff computers won’t have that problem.
July 16th, 2009 at 5:23 pm
Nice. Also on a related note, my laptop can render this at 30-50 FPS with around 50 – 80 objects. But pressing Collapse shoots it down to 12 frames. (This might be due to me using Windows 7 though).
>but apparently 10 year old email addresses aren’t worth much.
Mine does
July 16th, 2009 at 9:56 pm
Hey man, nice work, this is truly amazing… I noticed there is no floor friction when the marbles land on a moving floor. Probably not that hard to implement.
Amazing.
July 17th, 2009 at 2:53 pm
This is nice man. All the comments I had were basically already said above. Will we have the option to change the gravity variables in the final product? That might open up new difficulty levels.
July 17th, 2009 at 3:17 pm
I don’t see why gravity couldn’t be customized per-level. Or even controlled by a switch in-level. Probably something that should be used sparingly.
As for the level collapsing, that’s just a toy, I have no plans for a real level to do that. At least not all of it. This many moving objects should never happen in a real game. I don’t anticipate more than ~50 at once.
Dan: Ha, I’m surprised anybody noticed that. The moving platform is currently a hack – it doesn’t have proper motion in the world, I’m simply setting its position every frame, so it doesn’t behave quite like a normal moving object should.
July 18th, 2009 at 1:27 am
how many people do you have on this mailing list? You should start a facebook group. Definitely some networking power there. I’ll join, and invite my 500 and some friends, and the 1200 people in my group. Everybody needs jetpack. haha
July 18th, 2009 at 6:06 am
Nice work! Even if it does end up looking like this, I’d be over the moon!
July 18th, 2009 at 8:25 am
Actually we have a facebook fan page, which I think is about the same as a group. That’s the problem with no sidebar on this blog. We need the room for SWF’s, but there’s not much room to cram links without it getting cluttered. I’ve found a place to stuff the link in the header.
July 19th, 2009 at 12:28 pm
Looks great! I only get slowdown with a LOT of balls on the screen, or with the cool collapsing feature.
Is the background fractal noise/cloud image dynamically generated?
July 20th, 2009 at 11:44 am
Caught wind of this on TIGsource, I remember playing Jetpack when I was a kid. Don’t think we ever bought it though, so I guess I was stuck with the shareware version. In any case, very cool, very exciting stuff. Good to see.
July 22nd, 2009 at 10:44 am
Absolutely LOVED the original. Keep it up!
July 23rd, 2009 at 2:10 pm
If you collapse everything, then push R, it infinitely resets (and regenerates clouds over and over)
July 24th, 2009 at 9:20 am
Tim: Hmm that’s odd. I didn’t notice that. Well it’s kind of cool looking at least.
Yes there’s a nice little function in Flash to generate perlin noise.
August 15th, 2009 at 2:33 am
I love the physics, Adam, but I’m sorry that I couldn’t find any problems with it besides the ones the others pointed out! It’s nice to see so much progress being made upon returning from camp. I think gravity switches would be cool, and maybe having something come up in the game sometimes where you can collapse a couple bricks or stones or maybe even a whole row.