Building machines
(Originally posted on Mastodon)
I’ve started working on the system to build machines, which will be a central aspect of the game.
Nothing fancy so far, but I’m making progress. I still need to make wheels that actually roll, add the possibility to lock the direction, and this should already allow building a vehicle.
All in all, I feel this is easier to do with Godot than my first prototype with Unreal Engine.
Here I’m stress testing a bit the system, and already found emergent gameplay out of a single non-resizable dumb rectangular part 😉 You can build a bridge, even though you don’t have the right parts, and also that you can’t (yet) lift or otherwise move your contraption, and deleting parts is not implemented either. Which means you have to find creative ways to tilt the orientation of the thing during construction and be careful about the weight balance.
On the technical side, the system is quite simple. The beam part is a small Godot scene consisting of a rigid body with a box collider and box mesh (placeholder graphics). You can then instantiate this small scene at will. Of course I also have some code to cast a ray from the camera through the mouse cursor to find the point where the part should be placed.
To attach two parts together, I don’t use joints (would be bad for performances and physics engine stability). Instead, I merge the rigid bodies, and add all the colliders as child nodes (and also update the total mass). So, the final bridge is a single rigid body. I still have to write some more code to correctly merge multiple inertia tensors. Godot usually makes these computations for you, but it works only in the case where the matter density is the same for all colliders. Here if I was to attach a lightweight wood part to a heavy steel part, it wouldn’t compute the correct mass distribution.
Another note is that it’s not meant to work that way in the final game, such a structure should not be a dynamic rigid body. You’ll be able to choose if you want your design to be dynamic (like a vehicle) or static (for a building, a bridge, etc.) Either way, you’ll be able to use a common set of parts, to make an articulated vehicle or a hangar door, water lock, or anything you can imagine (hopefully).