• entries
  • comments
  • views

3D Platformer

Sign in to follow this  



So I saw an advert for Super Mario 3D on the 3DS on TV the other day and I thought to myself, wouldn't it be nice to just stop worrying about complicated physics for a bit and just write a platformer like I used to, just based on axis-aligned bounding boxes.

Then I thought, if I'm going to do that, it isn't a huge issue to do it in 3D instead of 2D. If I keep the camera oriented down either the Z or the X axis, I can just use four directional keys for movement instead of two, same system with a jump button, but have a retro-style platformer in a three-dimensional environment.

And, of course, it turns out to be trivial to extend the kind of old "physics" I used to use for 2D platformers to 3D platformers.

The major appeal of the simplicity of an AABB-based platformer is that over recent years I've been developing stuff using physics engines, mainly Box2D, and found that in exchange for the nifty features, I have to sacrifice so much creative flexibility and end up almost being driven by the physics engine in terms of what features I can put in my games.

Strictly AABB-based physics isn't very next-gen but it creates perfectly fun games and gives me back the creative freedom to decide what features I want to implement, not which ones are going to be feasible within a given physics framework.

So the above is just a randomly generated 3D map with a white cube representing the player which can run and jump around the level with the camera panning to keep the player at the centre of the screen, as much to prove the concept to myself as anything. No idea where I'm going with this but I'm looking forward to developing something with my own physics implementation, however simple, again instead of struggling with and against some behemothic physics library.

No offence, Box2D. You know I love you lots.
Sign in to follow this  


Recommended Comments

[quote name='TheUnbeliever' timestamp='1329784335']
You might be interested in Mobigames's EDGE, if you haven't seen it. It was in one of the recent Humble Bundles.

Thanks, I'll take a look.

Share this comment

Link to comment
[quote name='Azh321' timestamp='1329798479'] Let us try the demo! Source would be cool too, I have been itching to make the jump from 2d to 3d ;) [/quote]

Well, the demo really doesn't do enough that it would be worth the bandwidth to be honest. Equally, the source is a total mess at the moment but I'd of course be more than happy to release it when it is a bit tidier.

All I am doing is setting up a 3D vector representing the player's movement each turn, then moving the Y part individually, checking against all the other boxes for a collision each time. If an intersection is found, I move the player back to be sat against the side of the box it collided with, then carry on checking the rest of the boxes. I then do the same for the X and the Z.

This has the disadvantage of requiring a lot more intersection tests (trivial for AABB and easily improved with spatial databasing) and the advantage over using a minimum separation distance that objects never pop through the corners of each other or get stuck on invisible edges, both of which can occur using something like SAT.

A 3D AABB intersection, given boxes with a position vector and half-width vector really is as simple as:

bool Box::intersects(const Box &other) const
if(p.x - s.x >= other.p.x + other.s.x || p.x + s.x <= other.p.x - other.s.x)
return false;

if(p.y - s.y >= other.p.y + other.s.y || p.y + s.y <= other.p.y - other.s.y)
return false;

if(p.z - s.z >= other.p.z + other.s.z || p.z + s.z <= other.p.z - other.s.z)
return false;

return true;

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now