Video game animation

By , last updated March 17, 2017


It was time to implement some animations in our game “Burnt Islands“. The task was to add a catapult that was going to throw stones at enemies from the distance. A catapult needs to rotate towards the goal and to throw stones in the right direction. The whole thing without animation would look really weird.

We use Blender for modelling our models. It is a great tool for indie game developers.

Making an animation itself was not a problem. There are plenty of tutorials about it on the internet. The real problem was to export the animation from Blender and import it into the game so that everything runs correct.

Here I’m gonna show how I manged to do it after several days of troubleshooting.

Blender animation with NLA editor

Import or create a model

I going to to animate a catapult model in Blender
Import or make an object in Blender

Add a skeleton

I’m going to make an animation of the catapult. Add a bone armature by choosing Add -> Armature -> Single bone
Add a single bone into the scene

I choose a left-side view. Choose the bone and click on object -> X-ray in order to see the bone through the mesh (look at the menu to the right).
Choose a left side view and add an armature bone

Scale the bone by pressing “S” (although it is not necessary, it will be just easier to choose the bones if they are bigger).
catapult_3

Assign the bone to the object

Assign the bone to the object by choosing the object first and (while holding a Shift) a bone and clicking Ctrl + P -> With automatic weights. In my case it was not only one object I wanted the bone to be assigned to. I did join them before I assigned the bone.
Assign a bone to the object in Blender

Check that the bone is correctly assigned to the object by choosing the bone in “Pose mode” and dragging it. If everything is right the object should go along with the bone.

Check weights of the object that you assigned the bone to. Choose the object in “Object mode” and then choose “Weight paint”.
Choose weight paint for the object in Blender

An object that is totally assigned to the bone correctly should be all RED.
Assigned object to the bone in weights in Blender

Use the brush to make it red (left side menu).
Use wieghts brush to assign weights to the object in Blender

Dope sheet

After I have checked that the bone is connected to the mesh I choose a left-side view and make a new window for the “Dope sheet” by pulling a right up corner of the 3D window down and choosing a “Dope sheet” view. This view will allow us to make key frames of our animation.
Dope sheet view window in Blender

Key frames

Click a “Key frames” button down the window in order to automatically¬† insert key frames.
Key frames button in order to automatic insert key frames in animation in Blender

To insert the first frame click “I” and choose what type of animation you are going to use. I’m going to just rotate the arm of the catapult, so I choose “Rotation”.
Click I in order to insert a key frame in Blender

Move “the green line” position in the “Pose view” to a place where you want the next key frame. I need the arm to move fast up, so I choose to move 25 frames ahead. Then choose your bone in a 3D view and rotate (“R”) it up.
Rotate the bone and insert another key frame in Blender

I want the arm to move slowly back, so I choose frame 100 as my next keyframe place and rotate the arm back to start position.
Rotate the bone back to start position

B3D exporter and NLA editor

The best animation file extension is said to be b3d (Blitz3d). In Blender version 2.6 and higher it is available as a plugin that can be enabled by File -> User Preferences -> Addons -> Import-Export B3D (check the box). It is a Gandalfs exporter.

The main thing to remember here is that you need your animation to be exported as data strips. For that you use an NLA editor. Pull a new window and choose “NLA editor“.
NLA editor in Blender

Within an NLA editor you export your animation data by clicking a snow sign (on the left orange strip).
CLick snow to export data in NLA editor

Then you will be able to see your animation in NLA editor.
NLA editor animation strip in Blender

Export animation as B3D

Play your animation and make sure everything is correct. Then export your animation as a B3D file.
Export animation as B3D file in Blender

Video tutorial

Watch a video tutorial about how to make an animation with Blender and export it as a B3D file.

Irrlicht

People use different graphics engines in their games. We use Irrlicht in “Burnt Islands“.

Import a B3D animation

In order to import an animated mesh into the game with Irrlicht see tutorial 4 “Movement”. Here is how we use it:

ISceneNode * IrrlichtCreate::loadMesh(ISceneManager * mgr, const vector3df & position, const vector3df & scale, const std::string & filename)
{
	scene::IAnimatedMesh* mesh = mgr->getMesh(filename.c_str());

	auto *node = new CAnimatedMeshSceneNode(mesh, 0, mgr, -1 ) ;
	node->setPosition(position);
	node->setScale(scale);

	return node;
}

Irrlicht problem with Blender B3D exporter

As we imported the b3d mesh exported from Blender into the game we got a fail result:

screenshot_20140404T124643.438606screenshot_20140404T124645.082700screenshot_20140404T124649.815971screenshot_20140404T124651.501068

After several days of trying and failing I found out that an initial Blender exporter does something with both materials and vertexes and exports everything fail.

Blender B3D exporter fix for Irrlicht

A solution to a fail exported B3D file form Blender was a program fragMOTION.

Import your B3D file into fragMOTION.
Import B3D exported form Blender into fragMOTION

Check the animation. If something looks weird like mine was, you need to fix it. In my case there were some weights that were not totally 1.0 for the bone.
Not all weights are right in animation in fragMOTION

Export it again as a B3D file from fragMOTION.
Export animation as B3D file from fragMOTION

I needed to uncheck a “Hierachical mesh” checkbox.
Uncheck hierarchical mesh checkbox in fragMOTION

Results

The result is a correct animated mesh in your game!

screenshot_20140404T125242.770159screenshot_20140404T125244.443255screenshot_20140404T125246.125351screenshot_20140404T125248.536489screenshot_20140404T125250.207584

Senior Software Engineer developing all kinds of stuff.

Comments

Be the first to comment.

Leave a Reply


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*