Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a minecraft-like clone and was wondering what is the best way to go about animating a model, for example implementing the following feature: when the player presses the arrow keys, move both legs in the opposite directions but when the player stops moving retract the legs, slowley. This is what I want to be able to do dynamically, the following is just an example of what I want to acheive and is proberly not the best way of doing so.

So here is an example of what I mean, some thing like:

if (player.Velocity != Vector2.Zero)  {
} else {

I highly doubt that is a great way about going about animating the legs, but I hope you get the idea. Also, I wondering how would I actually use/create my model class so I can add animations to different objects.

Here is some pesduo code :

Animation animation = new Animation("Leg Rotation");
animation.Mesh = playerModel.GetMesh("LLeg");
animaiton.RotationType = RotationType.RotationFromOrigin;
animaiton.Axis = Axis.X;
animation.MaxRotation = MathHelper.ToRadians(25);
animation.MinRotation = MathHelper.ToRadians(-25);
animation.DefaultRotation = MathHelper.ToRadians(0);


if (player.Velocity != Vector2.Zero)  {
    player.Model.PlayAnimation("Leg Rotation");
} else {
    player.Model.PlayAnimation("Leg Retract");

Altough that is hardly sufficient as you cannot change the speed of the animation based on the speed of the player, and I don't think that is how minecraft does it...

So what I am asking is if anyone has any ideas on how minecraft does/handles animations or any other advice on how I should animite primitive models (in a reusable way) please help me :)

share|improve this question
up vote 0 down vote accepted

I think you are on the right track. You want to increment animation based on time and in this case the player's velocity. Instead of having a PlayAnimation method being called in the loop, I would have a SetAnimation method that gets called when the player starts walking. The the loop, you call a method that advances or calculates the animations next frame by passing the time passed since the last frame. Now you can multiply the time since last frame with the player's velocity to increase the walking speed.

share|improve this answer

Your Answer


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.