In this nice tutorial, the character is given an action (walk cycle) triggered by a controller. However, the actual movement of the character is caused by the controller literally translating an invisible box -> this is done for performance reasons.
However, I want to simulate a physically accurate body (bounds defined by convex hull) such that it is able to “push” off the ground with its legs instead of the controller literally translating the object. Ideally, the leg moves a little bit and pushes against anything it bumps into, applies torque, etc. The action is not very complex: just a small change in joint rotation.
Is there a simple way to do this via Python Script?
A realistically simulated walk is an incredibly complicated thing; Systems such as Euphoria have had teams of programmers and artists work their asses off to get it working. Here’s the best I’ve come up with for making it in Blender:
Rather than using convex hull, build the body physics mesh out of separate objects which are all connected by rigid body joints (a cylinder for the shin, connected to the thigh cylinder via rigid body joint, etc) basically how you would set up a ragdoll. Set your armature joints to copy the rotation of the objects such that they match up.
Now comes the tricky part: You’ll need a separate armature with the same bones, and run your animations on this invisible armature. Get the location and rotation of each bone (doing this may be easier if you parent an empty to each bone, in the same position as the rigid body objects would be). Now you have a target location for each bone in the ragdoll setup; just calculate how far away from the target position the bones are, and apply force to the rigid body objects to push them in the right direction. Now your ragdoll objects have a walkcycle, and because you have an armature copying the rotation of the ragdoll objects your character follows the same walkcycle; because the walk is on physical objects it should interact with the world correctly, including friction, and hopefully walk itself forwards. As long as the armature with the walk cycle matches the average location of the ragdoll objects (so they’re not just being pulled back to the start position all the time) this in theory should work. However, I haven’t tested it at all so I can’t say for sure.
The method of Captain Oblivion might work, but it won’t stop the walk cycle when bumping into objects (you might do some weird steps in the same position). If you would only want to push objects away more accurately you can parent collision shapes to the bones to resemble your character instead of a big bounding box.
If you want real feedback so that objects slow you down and can cause you to stumble then you get into complex stuff. I have been playing with ragdolls to the point they can walk an obstacle course (by cheating on the physics) but it is very difficult to get some good walk animation. So my experience with animating ragdolls, best avoid them unless you really need the physical interaction.
Fixed armature animations will probably get you the smoothest walk animation and you can also do complex stuff like aligning feet to sloping floors etc. (don’t ask me how, I just know it is possible :eyebrowlift:)
So it depends on what you really need which works best for you. And “performance reasons” is usually a very good argument, also considering the amount of work for the alternatives…