I found the open source cartwheel project a while ago and tried integrating it into unreal. Cartwheel is used to control articulated biped characters. It supports the following.
- Inverted pendulum foot placement
- Uses the Jacobian transpose to compute torque gravity compensation and to apply a virtual force to help regulate velocity
- Reacts to external forces e.g push / hit character. It also adjusts to match the character’s weight distribution e.g backpack, carrying a large gun in one arm (lean).
- Can create different walk styles which can be applied to different character types e.g drunk walk applied to giant or dwarf
- Can set target direction, movement speed, step height. Reduces leg overlap on turning
- The demos show tasks like reaching, pulling and pushing a crate, lifting and moving a crate, navigation over and under obstacles, stairs and crowd simulations.
The videos from the site explain it better.
The base code has been slightly modified to compile in unreal (c classes => c++, ignore warnings etc). It would probably be better to just use a library. Some of the python scripts have also been ported. It’s all been hacked together because I just wanted to test it. I probably won’t continue working on it due to performance issues.
The main downside I found with cartwheel is that the simulation requires a very small time step to be stable (2000 updates per second). After around three characters the frame rate dropped below 30 fps. Another problem is that a lot of the samples in the videos aren’t included in the python scripts. The ode and unreal coordinate systems also don’t match.
Code setup
Download the cartwheel original source from here(required to convert styles)
Create a project called “Cart” so you don’t need to change all the includes.
Add the source code.
Open Cart.Build.cs and update the include paths.
Add a SNMApp actor to the scene. In the cart group make sure both checkboxes are ticked, that “Smulation Seconds Per Second” = 1 and “Desired Simulation Timestep” = 0.0005.
Basic physics test
Add a plane. The add a CWRigidBody component. In the Cart settings group: tick “Enable rigid body”, tick “Locked”, mass = 1, Friction Coeff = 2.5, Restitution Coeff = 0.35. Then add a UCWPlaneCDP component as a child of the rigid body. In the cart settings: origin (0,0,0), normal (0,1,0) [NOTE: y axis is up].
Add a cube somewhere about the ground (y axis). Add a CWRigidBody component (same settings as plane). Add a CWBoxCDP component to the rigid body: top pos (-50,-50,-50), base pos (50,50,50).
Run the simulation and make sure the box hits the ground. From the left view the box should fall to the left and the ground plane will be vertical.
It just uses debug lines so it’s easier to see in wireframe mode.
Convert walk styles
If you just want to try the converted types included you can skip this step (Just add BipV3_EditableWalking from the Content folder inside the attached zip).
Walk styles can be created in the orignal Cartwheel app. Existing styles can be found in "cartwheel-3d\Python\Data\Characters"
Create two data assets. One CharacterControllerDataAsset called “BipV3_EditableWalking” and one CharacterControllerDAConverter called “Convert_BipV3_EditableWalking”.
In the “Convert_BipV3_EditableWalking” data asset assign the output to “BipV3_EditableWalking”.
In the oringal cartwheel source code find “cartwheel-3d\Python\Data\Characters\BipV3\Controllers\EditableWalking.py”. Open it and trim out the start and end and past in into the converter e.g should start with "name = " and end with “]”, not “)”. Or just use the attached file (BipV3_EditableWalkingExample.txt).
In the scene add a CharacterControllerDAConvActor and tick “Convert data” and set converter to “Convert_BipV3_EditableWalking”.
Run / stop the game then open “BipV3_EditableWalking”. Add any character to the name field and save (doesn’t seem to auto save on close if it hasn’t changed). Untick “Convert data” in the CharacterControllerDAConvActor or just delete it.
Adding the character
Make sure the BipV3 data asset in included from the download.
Add an empty actor. Add a InstantChar component. In the cart section set “character description” to “BipV3”, set “character controller data asset” to “BipV3_EditableWalking”, tick “Enable Character”, untick “Log controller” and tick “Override behaviour setting” if you want to control the character.
In the “Cart Behaviour” section update the setting to change the speed, direction etc. Note: behaviour heading are in degrees. This will only work if “Override behaviour setting” is ticked. Example settings for the character: “Behaviour Speed”:1, “Behaviour Step Time”:0.6. “Behaviour Coronal Step Width”:0.1, “Behaviour Heading”:20.
Extra
Try adding a box in front of the character or drop an object on them. The character should be able to handle collisions. If they do fall over they currently keep trying to walk (should be disable instead).
Some classes aren’t include from the original project including: ControllerPerturbator, HumanoidIKCharacter, RLState, UserInteractionPolicy. They might be worth checking.