In the previous part of the Panda3D series we used inverse kinematics in our slug model. Today we’ll be animating the model. We’ll be creating the first couple animations step by step and you can find all the animations in the blend file on github. Go ahead and open the slug.blend file in Blender.
There are several ways of animating bones in Blender, but what is important for us is that we should use animations as actions.
Let’s start with the none animation.
none Animation
First let’s switch to the Animation workspace (A) and make sure we’re in pose mode (B). Down in the Dope Sheet editor set the editing context to Action Editor (C). Next we must make sure that all bones are in their original positions. If not, select all the bones and hit Alt + G to reset location and/or Alt + R to reset rotation (D):
In the Action Editor make sure you’re at frame 1 (A). Then hit the New button to add a new action (B):
Rename the action ‘none’ (A) and hit the Shield button (B) to add a fake user. This is very important because this way our animation data will be saved even if the animation is not used. Otherwise we would lose it on leaving Blender. We must remember to add a fake user for each animation we create.
Our none animation, as its name suggests, hardly deserves to be called an animation because nothing is going to change here. That’s why we only need one frame for it. Set End frame to 1 (C):
Next, make sure all the bones are selected and, hovering over the 3D Viewport, hit I to add a keyframe. Then select Location, Rotation & Scale:
This will add keyframes for all the bones (A). I slightly dragged the border of the Action Editor (B) up so that you can see all the bones:
It doesn’t make sense to play this animation because nothing is going to happen anyway. Let’s let’s move on to the first actual animation, the idle animation.
idle Animation
So, hit the New Action button (A) to add a new action. Rename it ‘idle’ (B). Also, hit the Shield button (C) to add a fake user and thus permanently save the animation:
When you add a new action, all the keyframes from the previous action are still there for you. You can use them if you need or delete them. In this case we can keep them.
In this animation the slug will be moving his tentacles and also slightly his body. Let’s start with the former. To better see the tentacles, let’s switch to front view (Num 1) and deselect all the bones (A). If you go to the Output tab (B), you will see that the frame rate is set to 24 fps (C). This means there will be 24 frames each second. We want the idle animation to take two seconds, so set the End frame to 48 (D). Then we will be looping the animation in the game.
The tentacles should be in their original positions at frame 1 and 48. Halfway through the animation they should reach their maximum height.
So, go to frame 24 (A). Select the first bone of the left tentacle (B), which is actually the one you see on the right. If you go to the Bone tab (C), you can check the name of the bone (D). It’s Tentacle1.L:
Hit R -60 to rotate the bone along with all its children 60 degrees counterclockwise (A). Then hit I to add a keyframe and select Location & Rotation. This will add the appropriate location and rotation keyframes for the selected bone (B):
Then select the Tentacle1.R bone on the other tentacle (make sure the first one is deselected) and hit R 60 to rotate it 60 degrees clockwise (A). Hit I and select Location & Rotation to add a keyframe (B):
Now, we want to add a breathing effect. We can do it by slightly changing the scale of the bones. Hit Num 3 to go to right view, deselect all bones and then select all the bones along the spine of the slug (A). Naturally real slugs don’t have spines, but ours do. You can also drag the border of the 3D Viewport on the left (B) to make it occupy less real estate so that we can see the slug better.
Hit S 1.01 to scale the bones slightly and then hit I and select Location, Rotation & Scale to insert a keyframe:
At the end of the animation all bones should return to their original positions. The easiest way to do it is copy the keyframes from frame 1 and paste them at frame 48.
First select all the bones (A). Then select all the keyframes at frame 1. You can do it by selecting the topmost keyframe at this frame (B). Make sure the keyframes at frame 24 are deselected. You can tell this by color. The selected keyframes are yellow, the deselected ones are white.
Hit Ctrl + C to copy the keyframes. Then go to frame 48 and hit Ctrl + V to paste them there:
Save the file, go back to frame 1 by hitting the left Jump to Endpoint button (A) and play the animation by hitting the Play Animation button (B):
You should now see the slug breathing and moving his tentacles:
Stop the animation by hitting the Stop Animation button:
So, we’re done with the idle animation. Let’s move on to the walk animation.
walk Animation
Next, let’s implement the walk animation. This is the animation that will be played while the slug is walking to the racetrack or anywhere on the ground while not running.
Here, the slug should still be moving the tentacles, so we’re going to leave this as is. But apart from that, he should be lifting the middle part of his body slightly up.
So, hit the New Action button to add a new action. Rename it ‘walk’ (A) and hit the Shield button to add a fake user.
Now, as we don’t want to change anything about the tentacles, we’ll leave all the keyframes that are associated with them. We’ll also leave the keyframes on the other bones at frame 1 and 48 because at the beginning and at the end of the animation all bones should be in their original positions.
What we have to change is the way the body moves. So, deselect all keyframes in the Action Editor by hitting Alt + A and then hit B and box select the keyframes at frame 24 except the ones on the tentacles (B):
Then hit X and select Delete Keyframes:
Now, we want the animation two be three times longer than the idle animation. So, set the End frame to 144 (A). Go to left view (Ctrl + Num 3). Then select all bones and then all the keyframes at frame 48, which you can do by selecting the topmost keyframe. Hit G and move them to frame 144 (B). Next select all the keyframes at frame 24, hit G and move them to frame 72 (C):
Next, go to frame 1 and select just the body_IK bone:
Hit G Y 0.38 to move the controller bone to the left. This is where it should start off. Then hit I and select Location & Rotation to insert a keyframe:
Now select just the keyframe at frame 1 and hit Ctrl + C to copy it. Go to frame 144 and past it by hitting Ctrl + V:
Now go to frame 72. Hit G Y 0.01 to move the bone slightly. Then hit I and select Location & Rotation to insert a keyframe:
Test the animation. There are going to be more animations, which you will find in the blend file. They are all created in a similar way as those we just made.
In the next part we’ll test our animations in Panda3D.