Violent Sol Worlds has some interesting physics issues and where I left off last time was I had a proof of concept running with some primitive shapes doing collisions. That was not good enough for the game but showed we could do some decent detection and reactions in a primitive way. Where are we now you ask?
I focused on figuring out how to get complex polygons into the POC. The first thing that needed to be tackled was how do we generate the physics bodies in a way that is both quick and moddable. I found a perfect tool for the job, PhysicsEditor. You can find it here. It is the same company that makes Texture Packer and I have to say both tools are fantastic.
Using PhysicsEditor (PE) I was able to create our own file format in xml completely for VSW. The formatting was easy to setup and now the tool itself has an interface customized for the VSW option just by adding two files which we will supply with the game.
Here is the interface to add a simple physics object xml usable by my simple POC.
There you can see my sample "player" with it's complex polygon defined in red. You can also see the rest of the values on the right that give it its characteristics when it comes to the physics in real-time. The best thing about the tool is the xml it exports is clean and can be edited on its own so modders will be able to either pickup the tool or play around in text to alter the bodies.
Enough about the tool, right? It is fantastic, but what about getting it into the game? I was able to quickly get the complex polygon loaded into the engine and drawing to the world. Here is a little peak.
You can see the yellow outlines of the polygons drawing along with the circle outer bodies. You do not want to be doing complex polygon checks for every collisions only for precision. So the outer bodies must be colliding for a complex polygon check to be done, it saves cycles.
I also computed the normal's for the faces of the polygons which essentially are the collision normal's and the forces are in those directions. So I got those drawing as well. Here si a look at those.
You can see the short orange lines drawn at the middle of each face. Those show us that the face normal's are being calculated correctly. Now we have all the data in the POC engine and need to get the polygons colliding properly. How we do that is using Separating Axis Theorem SAT.
What is SAT?
The Separating Axis Theorem (SAT for short) essentially states if you are able to draw a line to separate two polygons, then they do not collide.
It is simple, but it did take some time and debugging to get it to act properly. When it was coded up and done it worked very well though in the POC. Here is a nice video of it in action in the POC.
Stay tuned to the next articles in this line to see how the rest of our physics story ends up.
Meanwhile go check out more articles on the development of Violent Sol Worlds at our main game page here. Also help support the team by checking out Cornflower Corbin as well. You can also make sure you know when we post any new updates by watching our project by clicking here. Thanks for all your support.