You have a problem. UFOs do not fly just by moving through the space. They usually rotate around themselves while moving in the different directions.
Now, we are going to add rotation capabilities to this 3D character.
1. Stay in the
3DInvadersSilverlight
project.2. Open
Ufo.cs
.3. Add the following
protected
variables. (The UFO has to keep track of the rotation angles and it has to rotate at certain speeds, both defined for each axis):// The rotation angles protected Vector _angleDegrees = new Vector(0, 0, 0); // The rotation speed for the three axis protected Vector _rotationSpeed = new Vector(10f, 5f, 0f);
4. Add the following
public
method to calculate the UFO's rotation angles taking into account its rotation speed settings for each axis and the elapsed time:public void CalculateNewAngles() { _angleDegrees.X = ((_angleDegrees.X + _rotationSpeed.X * (float)_game.ElapsedTime.TotalSeconds) % 360); _angleDegrees.Y = ((_angleDegrees.Y + _rotationSpeed...