Box2D collisions rendered in 3D with Away3D

Did you ever wonder what would be possible if you could merge a 2D physics engine with a 3D engine?

Roger Engelbert from Done With Computers, apart from having a blog with awesome posts (really! have a look!), tried to use Away3D to render Box2D collisions.

You will see the result by yourself.

« Here I’ll show you another way to build 3D collisions using 2D logic, by combining the Box2D engine with 3D rendering of elements. For this example, you must think of games where the 3D Y axis is not relevant (no change in altitude.)

In the game you can push the blue blocks, the larger one is harder to push around. And you cannot push the green cylinder. And when you shoot you a have nice recoil effect.

Here is the Box2D version of the “game”:

Use arrows to move, and space bar to shoot.

And here is the code for this version:

And the collision object for the sake of completeness:

Now in 3D I use the same Box2D code but I add 3D primitives. Here is the code:

And this is the result:

Use arrows to move, and space bar to shoot.

The code could be a lot cleaner and shorter if I’d used multiple classes, but I thought the example would be easier to understand if I used only one class.

One tip which I think is important would be to add some space between objects upon collision, in other words, make the collision area be slightly larger than the actual object. This will help with Z sorting. Sometimes in this example here, when you collide the player box with the blue boxes you can see the face segments get jagged and blink.

And the extra distance could be easily countered with a simple bump map in case it looks weird.

The problem of file size is however a big one. Box2D and Away3D are very heavy loads unfortunately. I’ll try to post the same code but with JigLib and see how that goes.

But I hope this helps with any ideas for 3D games you might have. I’ve seen race games using this engine, and third person shooters. They might seem very simple, but the number of fun games one could create with these simple ideas is amazing. And who says 3D has to be complicated!

Of course, uneven terrain in 3D can be a bitch…

Next I’ll do some line collision in 3D. »

  • Wow! This is a great example! Thanks for taking the time to put this out there.
    Exciting stuff.

  • Very awesome, it’s inspiring!

    I can even see making a FPS with this idea – just have to handle ground collision in another way… But there also other engines tailored for that.

    Now I have about 4 new game ideas though! Thanks!

  • Ze Ferreira

    nice demo m1gu3l

  • MC

    I can see the potential… Thanx!

  • Abmemar

    Please make the final step of Plants Vs Zombies !

  • bieron

    Another car game using box2d physic and away3d :

  • If you use the correct z-sorting renderer in away3D it should sort out your z-rendering correctly…. woah… (@_@)

  • Sam

    Nice work copying Roger’s blog!