Posts Tagged physics
I’ve been working on applying torques to the creatures in a meaningful and well thought out manner (read: banging my head against the keyboard whilst trying to fix all the horrible signage errors). The original intention was to simply pass the torques on to the energy system and let natural selection weed out the unbalanced and physically impossible specimens. But I realised I have the perfect opportunity to overhaul a system that has bothered me since its inception: the quadruped system.
Logically, if a creature has slightly smaller front limbs than back limbs, it should lean forward in order to walk on them (unless it’s a pangolin, but they’re too awesome to be swayed by our petty logic).
Without something to enforce this, every creature in Species ALRE would be a biped, because every creature has at least a *slightly* different leg size.
The quadruped system governs how this is implemented. A hideously simplified description would be “if the torso rotation is less than 45 degrees, and it has fore or back legs, the creature will fall forward onto its front legs or chest. If it’s higher than 45 degrees, or it has mid-legs, it will remain bipedal.”
That “45 degrees” is completely arbitrary. It’s just a value I picked.
This system is why ‘head-down butt-up’ creatures, whose bodies hang forward from their back legs are so common: Any creature with large back legs and a small torso rotation will end up with this body plan.
That’s the old system. The new one is much more sophisticated.
It starts by completely eliminating the quadruped system: creatures will initially be created *exactly* as their genes would have them (ie. with only one pair of their legs reaching the ground). It then calculates the skeleton and torques as normal.
Once that’s done, it passes control to the droop system. This applies “droops” to every body part attached to the torso: limbs, neck and tail. Legs are bent upwards by the reaction force on their legs, neck and tail are bent downwards, and the torso droops based on the creature’s balance, all in direct proportion to the torque applied on the joints.
If a body part droops into the ground, it stops drooping and adds a ground contact point, which will take some of the creatures weight in the next step.
Then pass 2 starts, the body-plan is completely reinitialised: bones are regenerated, torques and forces are recalculated. The results of pass 2 are what the creature will ultimately use for most of it’s energy calculations, so as to take advantage of the creature new quadrupedal body plan. (physical droops will affect energy, but proportionally to how much they rotate rather than as a function of torque. Small drops onto legs will be a negligible cost)
This also has a noticeable effect on creature appearances. I haven’t adjusted the rotation genes at all in the following screenshot: these variations are entirely the result of torso, neck and tail thickness changes causing different torques in the creature’s body plan.
One particularly noticeable change is that the creatures tail now has an effect: increasing its mass is the only way to counter the torque produced by the head and neck in the second body plan. For bipeds with centrally situated legs (raptor-like creatures), a sizable tail will be the only way to maintain balance (other than having an upright torso rotation gene and incurring a large energy cost in droop).
I’m hoping this system will be realistic enough to promote life-like body plans in place of a real-time physics system, which would be far too CPU intensive to implement across thousands of creatures. More likely, it will be exploited ruthlessly in ways I can’t yet imagine. But hey, that’s what makes it fun!
“Anime references. There goes the neigbourhood”
– Darker, linear arrows are Bones.
– Brighter, circular arrows are torques.
– Torque display arrows scale with torque magnitude.
– Torque Colour matches Bone colour (the orange torque goes with the dark-orange bone, which is the neck)
– Compressive and tensile forces are not displayed (though they *are* calculated).
– The creature was animating when this screenshot was taken, which is why the bones don’t match the leg.
– Torques are only calculated with Mass: reaction forces are not yet accounted for. Imagine the creature hanging from a string wound around it’s torso: those are the forces you see here.
– I’m not doing all this visualisation just for debugging: I intend to include the skeletal view (cleaned up, of course) in the final release.
I return, full of vip, vim, vigour and vampire babies!
I’m pretty sure my return to the lands of the self-motivated was prompted by a visit to the Tvtropes page for Dwarf Fortress. It’s strange how inspiring reading about Dwarf Fortress can be, especially given that I’ve never been able to actually play it for more than a few hours before giving up. Maybe it’s just my inferiority complex kicking in: I always feel like Species is an order of magnitude too shallow after reading about all the things DF does, which compels me to work faster to get the game to a state I’m actually satisfied with.
Work is still centred around getting the skeleton to fit the creatures exactly: I’ve got the rotations, but I’m having a basketload of trouble getting the lengths of animated bones. You’d think that’d be easy, but I’m having trouble working out what aspects of the bone matrices refer to what physical attributes.
(Edit) worked out the problem. I was multiplying the bones in the wrong order. Note to future self: multiply from the leaf bones first.
I’ve revised the plan for the skeleton heirachy in a way that, unexpectedly, is more radial than symettrical.
This should be a lot easier to code: force propogation becomes a one way street from the limbs to the stomach, and I don’t need to try and work out how the limb forces interact along the spine: I can just apply them directly to the hub and work out the equilibrium from there.
As you can probably guess, it’s also a step towards more versatile body plans. Necks, tails and limbs are still predefined objects, but as their base class absorbs more of their functionality, it will be much easier to turn them into a more generic “link” class that can be attached anywhere.
* * * * * *
With the skeleton finalised, it’s time to start working on the forces.
Heh. Comedic overreactions aside, it’s not that complicated. Most of the black arrows are bones, while the others are coloured by which bone they are acting upon. The first of each coloured arrows are mass forces. There are second arrows of some colours: these are Apparent Forces, or the forces *other* bones apply on their parent bones (for example, the disembodied yellow arrow is the force the limbs are applying on the shoulder bone). The three large vertical black arrows are not bones: they’re simply Apparent forces on the root bone, which is black and located in the center of the stomach.
Okay, maybe it is that complicated, but I swear it makes sense.
Oh, and I still need to add reaction forces at the ends of the limbs.
* * * * * *
The next step will be converting these raw forces into relevant ones: namely, compressive strength for each bone, and torque for each joint. In theory this is already done, but I haven’t visualised it yet, so I can’t confirm if it works.
With those in place, the game will finally have a framework by which to establish whether a creature is balanced or not. And if it’s not, it will have to expend energy or health maintaining its implausible body plan, which will encourage creatures to obey the laws of physics to avoid paying this price. I’m really looking forward to seeing that: practical restrictions should make the game feel much more physical and viscerally accurate, rather than the anything-goes abstract weirdness we have at the moment.