GTGameEngine – In-Editor Physics Simulation and Previewing
January 16, 2013
Posted by on
I find that one of the more frustrating things in game development is getting physics working properly. It’s especially annoying when you don’t have the tools easily available for proper previewing. Thus, what I’ve done is added support for previewing the physics of a scene through the editor. This is best demonstrated with a video:
Here’s how I do it:
- Serialize the scene to a memory buffer (needs to be restored afterwards)
- Enable physics simulation
- … observe physics …
- Disable physics simulation
- Deserialize the scene to restore everything back to normal
And that is it. It’s so damn simple, it’s a bit of a wonder why other engines don’t do this. But maybe they do and I’ve just not noticed. Let me know! (No, Unity’s “Play” button doesn’t count because I’m talking about ONLY physics simulations with nothing else.)
I serialize into a memory buffer instead of a file because 1) it makes things a lot simpler and 2) it should be a bit quicker.
The physics simulation is enabled and disabled through a single boolean. That boolean is just flipped when the simulation state changes. When physics is disabled, the editor simply neglects to call the physics manager’s Step() function. When it’s enabled, it calls it like normal.
My plan for much later on is to allow the user to leave an object where it was at the end of the physics simulation so that the physics engine can be used to position objects realistically rather than having them positioned by hand. I’ve go no idea how useful it’d be, but might come in handy for things like clutter or something…
And now for good measure, here’s another video of me playing around with the physics. Here I’m just testing the difference between different masses by watch how forcefully a ball pushes itself through a wall.
I can imagine this feature being especially useful later on when working with constraints. They’re always a pain…