ここでは「立ち」状態と「歩く」状態の間のクロスディゾルブのアニメーションブレンドの方法を紹介します。
○blendFactor という名の新しい float型のメンバ変数を追加して下さい。0~1.0fの間でスケーリングし、現在のアニメーションと目標のアニメーションの間でどのくらい混合しているのかを表現します。
// Add this as a member variable
float blendFactor = 0;
○入力に応じて、状態を変化をさせ、適切な blendFactor を設定します。「立ち」状態での変化。
// Add this to the beginning of the if (state=="idle") block in the UpdateState method
// Remove the old if (keyState.IsKeyDown(Keys.W)) block
if (keyState.IsKeyDown(Keys.W))
{
blendFactor = 0;
state = "idleToWalk";
}
○「歩く」状態での変化。
// Add this to the beginning of the if (state=="walk") block in the UpdateState method
// Remove the old if (keyState.IsKeyUp(Keys.W)) block
if (keyState.IsKeyUp(Keys.W))
{
blendFactor = 0;
state = "walkToIdle";
}
○ドワーフは「立ち」状態から「歩く」状態に移行いるとき、blendFactor を増加させ、アニメーションを設定し、適切な値でアニメーションブレンドを行います。次のソースコードを UpdateState メソッドに追加して下さい。
// Add this to the UpdateState method
else if (state == "idleToWalk")
{
blendFactor += .1f;
currentSpeed = blendFactor * WALK_SPEED;
if (blendFactor >= 1)
{
blendFactor = 1;
state = "walk";
}
foreach (BonePose p in poses)
{
p.CurrentController = idle;
p.CurrentBlendController = walk;
p.BlendFactor = blendFactor;
}
}
○ドワーフが「歩く」状態から「立ち」状態に移行しているとき、同じようにしたいと思います。しかし、blendFactor が増加するのに従ってドワーフが減速するので、速度をスケーリング(1 - blendFactor)します。
// Add this to the UpdateState method
else if (state == "walkToIdle")
{
blendFactor += .1f;
currentSpeed = (1f-blendFactor) * WALK_SPEED;
if (blendFactor >= 1)
{
blendFactor = 1;
state = "idle";
}
foreach (BonePose p in poses)
{
p.CurrentController = walk;
p.CurrentBlendController = idle;
p.BlendFactor = blendFactor;
}
}
最終更新:2009年06月21日 12:49