This code looks really good; I’m in the middle of developing a game and have decided that JME’s standard physics is overkill for me, and there doesn’t seem to be any other “simple” physics library. Can I just ask what particular problem this solves, or what features it has over and above standard collision checking?
Like you said it’s meant to be simpler, and better if you want more control over the physics (for either better character movement or maybe networking). I never solved the double collision issue above, and the papers that describe this collision detection don’t even mention the problem. Maybe you can solve it?
- Get picture of me.
So is it a drop-in replacement (-ish) for RigidBodyControl?
No not really. It has a lot less steps. If you look at my Gist above there is an example. Really you just define a collideable ellipsoid and apply velocity to it.
For what it’s worth, writing a simple physics library is drop-dead simple.
v = v + a * t;
p = p + v * t;
That’s physics. Done.
Even simple collision detection and restitution is not hard… if you only want spheres (or spheroids) and if you don’t care about rotational acceleration.
The problem is that as you start adding the “oh, but that’s still simple just not as simple” things… the complexity goes up exponentially.
“I want to support non-spheroids.” = complexity nearly at bullet level
“I want to support rotational acceleration/velocity in 3D space” = complexity nearly at bullet level
Otherwise, the math is only a few lines of code, really.
When I was looking for a “simple” physics library, I was looking for something that handled “simple” gravity (i.e. go down if nothing is in the way), notifies of collisions, and prevents intersection. It can treat everything like a sphere (or whatever’s easiest). And ideally works in the same thread as the main update thread. It can leave out things like rotation, mass, friction, restitution, acceleration, rolling, etc… Know ye of such code?
So while Bullet is pretty featureful you can just use whatever it is you want. Implementing simple gravity is ridiculously easy. As in when you create a rigidbody by default it has gravity and will happily fall endlessly without a floor collision object (For my space game I had to make sure to use setGravity(Vector3f(0,0,0)) to stop gravity from dropping my ships through the floor).
To stop things like rotation look through the forums for examples like here: Lock Z axis - #13 by m4tx
Edit: Basically saying to just use Bullet. It’s fine and not that scary once you follow the tutorials.
Nah, because it’s only like 10 lines of code. Anyone who needs it probably just inserts it where they want.
I’ve used Bullet lots of times for various games, and it works great. I’m writing a multiplayer FPS as the moment though, and it’s overkill for my needs. Such a game is pretty CPU intensive as it is, so I’m trying to streamline it. Also, it sometimes has some problems (e.g. falling through floors) which exponentially multiply the complications when making a network game.