Rigging and Animating a Creature in WebGL – From Blender to a Playable Three.js Game 5 Sections34 LessonsLifetime
Lesson 2: Applying Animation and Lateral Movement
This lesson sets up the IK constraints on the four limbs, positions the limbs with the IK bones, and creates a walk animation and an idle animation. A controller bone is then added so that the whole crab can be moved while an animation plays. The next lesson exports the animated crab.

What This Lesson Covers
- Disconnecting the IK bones and adding the IK constraints
- Setting the chain length so that each IK bone moves only its own limb
- Positioning the limbs with the IK bones
- Creating a walk animation with Copy Pose and Paste Pose Flipped
- Lifting the limbs and tilting the body during the walk
- Setting the interpolation to Linear in the Graph Editor
- Naming the walk animation and pushing it down in the NLA Editor
- Creating an idle animation
- Adding a controller bone that moves the whole crab
Disconnecting the IK Bones
The IK bones are still connected to the rest of the armature, so pressing G on one of them moves more than it should. Select each of the four IK bones and press Alt P (Option P on a Mac) to clear its parent.
Go into Pose Mode and make sure X-Axis Mirror is selected. Select an IK bone and press G. The matching bone on the other side moves with it.

Adding the IK Constraints
In Pose Mode, select an IK bone, then Shift-select the last bone of its limb. Press Shift and I together and select Target Selected Bone. For the front left limb, for example, select limb.F.IK.L and then limb.F5.L.
Select the limb’s last bone and open the Bone Constraints tab. The IK constraint is there.

Testing the IK on One Limb
Press G with the IK bone selected. Nearly everything on the crab moves, because the IK chain runs all the way back to the centre bone. A raised hand does not move the whole body, so the chain needs to be shorter.
Select the limb’s last bone, open the IK constraint and set the Chain Length to 5. This is the number of bones in the limb. Press G again on the IK bone. It now moves only as far as the limb.

Applying the IK to the Rest of the Limbs
Repeat the steps for the other limbs: select the IK bone, Shift-select the last bone of the limb, press Shift and I, and select Target Selected Bone. Set the Chain Length to 5 on each one. Press G on each IK bone to check that it moves only its own limb.
The IK constraint is not mirrored to the other side. Complete the right side in the same way, so that all four limbs have an IK bone with a chain length of 5.

Positioning the Limbs with the IK Bones
Turn off X-Axis Mirror, so that each limb moves on its own. In the front view, press 1, select an IK bone, press G and bring the limb down. Do the same for the other IK bones. In the top view, select an IK bone and press G to move the limb forward or back.

Testing a Render with a Floor
To see how the crab looks on a surface, press Shift A and add a Mesh, then a Plane. In Edit Mode, scale the plane up with S.
The crab already forms its shape on the floor and casts shadows. Delete the plane once the test is done, because it distracts from the animation.

Creating the Walk Animation
The walk runs across 60 frames. The timeline can be extended further if needed, but this lesson keeps 60 frames.
Start with an initial position in which all the bones are in one place. In Pose Mode, press A to select all the bones, and add a keyframe with I.
Press 7 for the top view. Pressing G, Y and 2 (or 3) moves a limb backwards, and G, Y and -3 moves it the other way. With X-Axis Mirror turned off, each side moves on its own. If the limbs move too far, press X, then G, and bring the bones closer to the body.
Turn on Auto Keying. From this point, every position that is set is recorded. At frame 30 the legs have swapped sides, and at frame 60 the crab is back in the starting pose. Select the keyframes at the start, press Shift D, and move the copy to frame 60.

Using Copy Pose and Paste Pose Flipped
The pose at frame 30 is the opposite of the first pose. Go to the first frame, select a limb bone and choose Pose, then Copy Pose. Go to frame 30, select the bone on the opposite side and choose Pose, then Paste Pose Flipped. Repeat this for each of the limbs on both sides.

Trying Out the Walk Animation
Press play to see the walk. The animation works, but it is slow. To speed it up, select everything and scale the keyframes with S. Pressing S and then 0.5 doubles the speed. Scaling the keyframes down to 18 frames makes the walk too fast.
Make sure that all the bones are selected first. If only one bone is selected, only that bone is affected. With all the bones selected, press S and set the walk to 30 frames, and set the end frame of the timeline to 30.

Lifting the Limbs
A crab lifts a limb when the limb moves forward. Find the point where a limb goes forward, not too close to the end of the cycle. At frame 6, select the limb bone and press G, Z and 2. At that point the back leg on the same step also lifts, so press G, Z and 2 on that bone too.
At frame 20, the other limbs move forward. Select those limbs and press G, Z and 2 on each of them. Play the animation to see the limbs lifting.
Tilting the Body
The body should also move when a leg lifts. The hind legs are stronger than the front legs, so when a front leg lifts, the body leans on the hind leg and tilts towards it.
Start the tilt before the leg lifts. In the top view, press 7, select the spine bone and press G, X and 0.5 to tilt the body at the point where the legs are lifted. Press Shift D to copy the keyframe, and move the copy to the point where the body returns to its normal position. Frame 15 is the middle of the 30-frame walk.

Setting the Interpolation to Linear
The movement is not yet regular. Open the Graph Editor, press A to select all the keyframes, right-click and set the Interpolation Mode to Linear. The movement is smoother.

Naming the Walk Animation
Open the Dope Sheet and select Action Editor. The action is named ArmatureAction. Rename it to walk_animation.
Right-click the area, split it horizontally, and select the Nonlinear Animation (NLA) editor. The walk animation appears there. Click Push Down so that the animation is stored in the armature. The track can be disabled, and then the animation no longer plays. Enable it and it plays again.


Creating the Idle Animation
Return to the Action Editor and click New to create a new action. Name it idle.
Go to the front view. The idle animation only moves the centre bone. In the top view, press 7. Press G, Y and 3 and then G, Y and -3, so that the bones return to their initial pose. Select the limb bones and press G to place them in the right position, then press G and Shift Z so that they do not move up or down. In the front view, press G and Z to put each limb properly on the floor.

Now animate the centre bone. Press A, then I to add a keyframe, and move the keyframe back to frame 0. The animation runs across 16 frames, so set the end frame of the timeline to 16 and use Shift D to copy the keyframe there. In between, move the bone to the left and then to the right. At the start, press G, X and -3 and press I. At frame 8, press G, X and 3, so the bone is on the other side.
Play the animation. It is too fast, because an idle animation should be slower. Select the keyframes and press S and then 2 to double the duration, and set the end of the timeline to 31.

Pushing the Idle Animation Down
Open the NLA Editor and click Push Down on the idle action. Both animations are now stored in the armature, and either one can be selected and played. A track that is enabled overrides the others, so disable the idle track to see the walk play.

Adding a Controller Bone
A controller bone moves the whole crab. Go to Edit Mode and press Shift A to add a bone. Select it, look at it from the side and rotate it down with R and X. To rotate it from its own position, set the Pivot Point to 3D Cursor, press 3 for the side view, press R and hold the Control key.
Turn on wireframe mode to see the bone.

Parenting the Bones to the Controller Bone
The controller bone is the parent. Select the bone to be controlled, then the controller bone, and press Ctrl P and Keep Offset. In Pose Mode, press G on the controller bone. It controls the spine bone.
The IK bones need to follow it as well. In Edit Mode, Shift-select each of the IK bones, then select the controller bone, and press Ctrl P and Keep Offset.

In Pose Mode, press G on the controller bone. The whole crab moves. While the walk animation plays, the controller bone can be used to move the crab forward.

Using a Circle for the Controller Bone
Changing the shape of the bone makes it easier to see what it controls. In Object Mode, press Shift A and add a Mesh, then a Circle. In Edit Mode, press S and scale the circle to a size that goes around the crab.
In Pose Mode, select the controller bone, open the Bone tab, and open Viewport Display. Set Custom Object to the circle. The circle now represents the bone, and moving it moves the crab. Select the original circle object, press G and X, and move it to the side.

Return to Pose Mode, select the controller bone, and go to the top view. Play the walk animation and press G. The crab walks across the scene.

