Controlling Cantankerous Monster Robots

After getting physics based climbing working I decided for some reason that climbing moving blocks was not interesting enough. So I tried to create some big monsters/robots to climb instead.

Three-legged Robot

As mentioned in the previous post, the climbing algorithm works by attaching two physics rigid bodies together. This means that the giant monster has to be made up of rigid bodies. So I can’t build monsters the typical way, using a mesh + skeleton + animations. Instead the monster has to be built using chunk of physics objects and joints. Basically, the monster is a big robot built with blocks and motors.

A Big Bug

Six legged bug

The initial test was really simple - a bug built with six blocks attached to a central block using joints. The joints can be driven which makes them behave as motors to twist the legs into desired position.

This worked pretty well, but there was a lot of blueprint coding and routing to properly drive all the legs. And these “legs” only had one segment! If I wanted more complicated monsters with multi-joint limbs and eyestalks and arms, I would need something better than simply hard coding motor values for each joint.

Monster As A Big Robot

Conceptually the monster is set up as a big robot, with the “body” being a big single physics chunk. Limbs are built using physics shapes as segments and physics constraints as joints.

Monster/Robot Diagram

In this way the monster is made up of only rigid body objects, and the player can climb any part of the monster. Unfortunately, the monster cannot be animated using Unreal’s typical skeletal animation system. Instead we have to manually control and move the limbs, as if controlling a robot.

Limb Control

The limbs can be moved by driving each joint to specific values. How do we find the proper joint rotation values? Finding these vales by hand takes a lot of time and work. A better route is to use Inverse Kinematics (IK) which computes the joint rotations that will position the end of the limb at a specific location.

IK Solver Visualization

In this case there is some code in an Unreal Blueprint that derives the joint rotations using an IK method called Cyclic Coordinate Descent (CCD). The IK joint rotations are found for each limb, and then joint motors are driven to those desired values.

Each tick the blueprint can set new target locations for each limb and recompute the IK values. So a simple monster can now be built to move legs around by setting the target endpoints each tick.