NikiTo said:
Once you have it walking, why not make it run?!?! Maybe you are defining your problem in the wrong way. The same logic should apply to running and jumping. You should not code a walker, then separately code a runner, then separately code a jumper. You need to define a something with two legs. In my opinion, if you do not define a something with two legs and keep from there, you are defining the problem in a wrong way.
I did not made it to the running because i had the issue of ragdoll falling on its nose occasionally and i did not know why, so i focused on that. I assumed my math is wrong, improved it, checked it… also made a good walking behavior instead that dumb state machine.
But nothing helped. I kept tipping over and falling to the floor, no matter what i did.
Finally i figured out the issue was Newton contact caching. After it refreshes contacts, it can happen they move from the front of the foot to the middle for one frame. And this means the foot can not apply so much force as the controller expects. Because humans are tall and their support polygon is small, this tiny inaccuracy is enough to tip over a second later. The ragdoll is doomed to fall, because there is no way to prevent it without making a step.
I fixed this issue with positioning the contacts myself, but at this time i already focused on GI and actually the ragdoll is broken because i changed too many things. So can't continue without spending weeks on this, and currently don't have time for that.
A similar issue was that i controlled joint motors with target orientation for the next frame. But because rotation angles are so small and quaternions can not deal with tiny angles robustly due to necessary normalization i had to switch to target angular velocity instead.
Such issues are really unexpected. You would think such tiny differences do not matter, but efficient balancing (meaning to move as fast as possible) requires really accurate simulation. No wonder toddlers need a whole year to learn it.
Ofc, we could solve such issues with cheating. By positioning the contact out of the actual foot balancing would become very easy (for me at least). Probably this is necessary for games, because they do not always aim for realism. Superpowers, moving unnaturally quick, etc.
But first i want to do it right so i learn it properly, and if i do it right it will look real without any need for animation. (And it could drive real robots :D )
There are many ways to tackle this problem. My approach is just one of many, but it certainly is not wrong. Ofc. i'd like to have a general solver that makes no difference between walking, running, or any other motion. But first i need to understand both physics and motion planning, and you can not write a solver for a problem you do not fully understand yet. The first step is done, which is the balancing controller that is general for running, walking and any upright motion of bipeds. (though, useless for snakes - but their motion would be easy to model in comparison)
Maybe i can replace the analytic pendulum model with some general solve of an optimization problem in a far future, but having hardcoded subcontrollers for walking, running, crawling or climbing could end up faster and easier to tweak for desired results. Downside is it wont work for animals without extra work.