Collision detecion in a 2.5D game?

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
Marian Schedenig
Gnoblar
Posts: 13
Joined: Sat Sep 24, 2005 4:21 pm

Collision detecion in a 2.5D game?

Post by Marian Schedenig »

I'm wondering how to handle collision detection in the 2.5D game I'm making. It's a conversion of a plain 2D game I made 10 years ago, so while the models and rendering are 3D now, the game mechanics are strict 2D.

Ideally I'd have pixel perfect collisions based on the non transparent pixels written to the colour buffer. I imagine some trickery with the depth or stencil buffer could work here (my OpenGL is still a bit rusty), but I don't know how performant it would be (given that I guess I'd need multiple render passes to accurately determine which two actors are colliding). More importantly, it would tie my game logic to rendering rate, which means that I would lose collision detection for some frames in case the render loop runs slower than the game logic updates.

Alternatively, I could aim for detecting the collisions between the 2D projections of my models (or collision models - not pixel perfect but probably good enough). Though if I'm going the mesh collision route anyway, I'm not sure if it's actually worth doing the projections or if I should just expect actual 3D collisions to be accurate (or, more importantly, "logical"/obvious for the player) enough.

In this case, I'll need a collision library, and that apparently means a physics library. I don't need any physics functionality, and not even any advanced collision features - just recognising when a pair of meshes collides is all I want. So I'm looking for a lib that handles low level collisions easily and quickly, integrates well with Ogre (by that I mean that I'd like to load my collision meshes as Ogre resources and be able to easily convert my Ogre transformation into whatever the library needs - I don't need any automatic frame listener integration, as I'm driving my own main loop anyway), has a non restrictive licence (and is ideally open source), supports the usual platforms (at least Win/Linux/OSX, but Android and iOS would be good as well) and has up to date Ogre integration (I'm using 1.9, but who knows when I'm actually going to finish this project, so it should be something that's in active development and expected to have updates when the next Ogre version comes out).

I understand this is largely a FAQ, but from looking around, I'm still not sure which of the usual suspects (e.g. Bullet and Newton) actually have up to date Ogre bindings, plus I'd be interested what others think of my detection alternatives, especially if going the 2D projection route might be feasible with a physics engine and which would be the best candidate for that.
User avatar
Daixiwen
Greenskin
Posts: 105
Joined: Fri Feb 08, 2013 11:30 am
Location: Oslo
x 16

Re: Collision detecion in a 2.5D game?

Post by Daixiwen »

MOC and new MOC are fully integrated with OGRE, but from what I can see from the source code, they only support raycasting (i.e. collision between a mesh and a ray). Besides they are written for v1 meshes, so they will need to be adapted if you plan to use Ogre 2.1.
There are some wrappers to use bullet with Ogre entities, but it may be overkill to use a full physics engine just for collision detections.
Some engines like ODE have separate collision detection and physics simulation phases, and it is possible to use only the collision detection part.
There is also libccd, a library specifically for collision detection (and actually libccd is a part of ODE for the collision detection of complex meshes).
In the last two cases, you will have to read the mesh data yourself and provide it to the library in the correct format. I think it's sill easier than doing yourself the 2d projection and the collision detection after.
Hardware, n.: part of the computer you can kick
Post Reply