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) {
player.Model.PlayerAnimation("LegsWalk");
} else {
player.Model.PlayerAnimation("LegsRetract");
}
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);
model.AddAnimation(animation);
...
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 :)