DevBlog - Driving Demo

»

Here's some exciting stuff, for sure!

After some deep dives into the mysteries of box2D and a lot of peeking on the testbed, results are marching forth like ants to a picknick! With help from the Input class included in the box2d packet and a little nifty programming here's a "playable" demo. Well sort of playable, you can at least drive back and forth (arrows). Now watch the magic of a physics library as you drive over the crates on the right.

To achieve controlled movement of the tank I simply apply a torque on both the wheels if the right button is pressed. I think it's awesome just to drive around! Do you remember my game sketch? The tank is implemented exactly like that:

  • A playerAI that listens for keyboard input and gives commands to the tank.
  • The tank translates "moveRight()" into "applyTorque(POWER)" to the wheels.
  • Box2D does the rest!

There are two other things to notice in this demo.

First, you notice that I have made a VCam. That is, a camera that follows the tank when you drive around. This is actually very easy to do, you simply put all of your graphical assets into a single container (ie. a DisplayObjectContainer for example a Sprite). Then if you want to move the camera to (X, Y) you simply move the container to (-X, -Y). Add some bonus if()'s and slap it into a class and you're done.

Second, we can see stuff? Everything you see is actually drawn by Box2D, which includes functionality to draw all bodies for debug purposes. Talk about useful! This is only included since the latest version of box2D (2.0.?). Before that the testbed included some functions for drawing the bodies and joints, but this is much better. The only exception is the gray part of the tank which is a (eeh not very advanced) movieclip I slap on (match the bodies position and rotation).

Okaaaaay, enough ranting - go try it out again. How does it feel you guys, let's have som opinions!

Submitted by Fickludd on Sun, 05/04/2008 - 22:00
Visitor Says:
Mon, 06/09/2008 - 13:28

The physics are the key of what makes this so good... I always thought it would be cool but wondered why you wanted to use Box2d so much.

Now i realise; I never thought you'd actuaally have physics controlled tank tracks and environment and omg it is SO GOOD! I love it so much.

All I can say is the tank moves too slow. WAY too slow.

Fickludd Says:
Fri, 06/13/2008 - 00:08

The physics are awesome :D. Yeah I have some lag issues in this version, but if you watch the latest one it runs much better (about 50% faster).

James (not verified) Says:
Mon, 05/05/2008 - 21:29

Physics is fun. I should definitely take a look at this for future game ideas.

^_^