Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I would like to know how the animation system works in minecraft. I get a feeling that all the mobs are hardcoded into the game. Did notch really sit there and create the matrices for all the animation bones by hand?

I like recreating games for fun, so I would like to know how he did this. Also, if he truly does hardcode them... is there a better way?

share|improve this question
2  
why do you think he may have hardcoded animations? –  Ali.S Oct 2 '11 at 16:51
    
Seems like this question is only answerable by Notch. –  Byte56 Oct 2 '11 at 18:01
9  
More to the point, why do you care how Minecraft did it? Do you have an idea on how to accomplish the same thing some other way? –  Tetrad Oct 2 '11 at 19:37
1  
minecraftforum.net/topic/361430-181smp-smart-moving The maker of this mod might have an answer for you but animation is not an area of the minecraft code I have looked through before. –  James Oct 3 '11 at 2:59
1  
I've looked through the MCP code before, and I'm 99% sure I remember seeing the animations hard-coded. I no longer have minecraft (or even Eclipse) to check, though. –  BlueRaja - Danny Pflughoeft Oct 3 '11 at 6:28

2 Answers 2

up vote 17 down vote accepted
+250

As others have said, yes the models as well as the animations are hard-coded. If you would like to see how this was done, go to the Minecraft Coder Pack wiki.

The package was created to help mod creators to decompile, change and recompile the Minecraft classes. Instructions are included in the readme files which come with the package. The package contains scripts to decompile, recompile, and reobfuscate the game and the server.

The classes you will want to look at are: ModelBase, ModelBiped, and ModelRenderer.

ModelBiped contains the following functions which do the humanoid animations:

public void render(Entity entity, float time, float f1, ...)
{
    setRotationAngles(time, f1, ...);
    ...
}

public void setRotationAngles(float time, float f1, ...)
{
    ...
    bipedRightArm.rotateAngleX = MathHelper.cos(time * 0.6662F + 3.141593F) * 2.0F * f1 * 0.5F;
    bipedLeftArm.rotateAngleX = MathHelper.cos(time * 0.6662F) * 2.0F * f1 * 0.5F;
    ...
}

The arm swings are simply cosine functions. The right arm is offset by PI to make them swing in opposing directions.

graph of the arm swings

I hope that answers your question =)


If you would like more information on how to actually mod Minecraft, then check out this question:

How do I add a custom mob to Minecraft?

share|improve this answer
    
Thanks! this is exactly what I was looking for. –  radenon Oct 9 '11 at 17:45
    
Sis! Euclidean rotation :(. –  Jonathan Dickinson Oct 10 '11 at 8:04

Models in Minecraft are hard-coded. There is no notion of block hierarchy (only a list of blocks). This means animations are either done procedurally (in a very basic way) or hard-coded values with interpolation.

There are a few editors for Minecraft models like Techne or FMCModeler which allow importing / exporting Minecraft model code for mods, but they don't support animations since it is probably handled differently for each model.

Here's a quick sample generated with FMCModeler:

//variables init:
public ModelRenderer box;

//constructor:
box = new ModelRenderer(0, 0);
box.addBox(0F, 0F, 0F, 16, 16, 16);

//render:
box.render(f5);

A better way to do it would be to build a full block-based modeler with some notions of block hierarchy so you can animate the models with keyframes and interpolation.

I'm currently building a multiplayer game building tool which does just that (among other things, http://craftstud.io/). It already allows building complex static textured models and more is on the way.

Here's a complex model built with CraftStudio As you can see, the blocks are arranged in a tree on the right: http://i.stack.imgur.com/FRQeV.png

Each block is serialized to disk / over the network with the following data:

  • Unique ID
  • Parent node ID
  • Position (affects descendants)
  • Scale (affects descendants)
  • Angle (affects descendants)
  • Offset from pivot point
  • Block Size
  • Block texture offset (UV coordinates offset for the texturing)

I plan on adding animation support by storing a map with animation names as key and a list of keyframes as value. Each keyframe will be associated with a block and a value to animate. Between keyframes, values should be interpolated (either linearly for position or spherically for angles, search for lerp and slerp).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.