Time for action – tank animation
In order to animate our tank, we perform the following steps:
1. In the constructor of the
Tank
class, add the following two lines to the end of the method:baseTurretTransform = model.Bones["turret_geo"].Transform; baseGunTransform = model.Bones["canon_geo"].Transform;
2. In the
Draw()
method of theTank
class, add the following before the call tomodel.CopyAbsoluteBoneTransformsT
o()
:model.Bones["turret_geo"].Transform = Matrix.CreateRotationY(TurretRotation) * baseTurretTransform; model.Bones["canon_geo"].Transform = Matrix.CreateRotationX(gunElevation) * baseGunTransform;
3. In the
Update()
method of theTankBattlesGame
class, add some temporary code to allow us to animate the tank with the keyboard. Place this code after the existing camera movement code, inside theif
block that checks for (this.IsActive
) — directly after the current mouse position is stored inpreviousMo
use
:// Begin temporary code KeyboardState ks = Keyboard.GetState(); if (ks...