title: XNA Vector math: explanation of code (different Vector2D, same movement on screen)
body: <p>I've followed <a href="http://www.3dbuzz.com/vbforum/sv_home.php" rel="nofollow">3DBuzz's</a> XNA AI tutorial and it uses vectors to calculate object directions. I'm having trouble understand a simple piece of code that moves an object in a given direction (The 3DBuzz videos don't really dig deep into the vector math).</p>
  
  <p><strong>A bit of background</strong></p>
  
  <p>The AI system uses Actor classes which you can assign Behaviors. Behaviors have a set weight property defining how much of the behavior is taken into account when working with multiple behaviors. Below is a behavior for moving an object in a constant direction. This is the update method, being continuously called. </p>
  
  <pre><code> public override void Update(Actor actor)
   {
       actor.Direction += this.direction * this.Weight;
   }
  </code></pre>
  
  <p>The thing I don't understand is, <strong>why does my object move in a constant direction while the Actor's Direction variable is incremented with that direction each frame?</strong> </p>
  
  <p>Initially I thought it was because the Direction vector is normalized on each update in the Actor class, but when logging my direction before and after the normalization, they're both different. This is my output (Trace.WriteLine):</p>
  
  <pre><code>DIR: {X:0.7071068 Y:0.7071068}
  NOR: {X:0.7071068 Y:0.7071068}
  DIR: {X:2 Y:2.537759E-27}
  NOR: {X:1 Y:1.268879E-27}
  DIR: {X:0.7071068 Y:0.7071068}
  NOR: {X:0.7071068 Y:0.7071068}
  DIR: {X:2 Y:1.268879E-27}
  NOR: {X:1 Y:6.344397E-28}
  DIR: {X:0.7071068 Y:0.7071068}
  NOR: {X:0.7071068 Y:0.7071068}
  DIR: {X:2 Y:6.344397E-28}
  NOR: {X:1 Y:3.172199E-28}
  DIR: {X:0.7071068 Y:0.7071068}
  NOR: {X:0.7071068 Y:0.7071068}
  DIR: {X:2 Y:3.172199E-28}
  NOR: {X:1 Y:1.586099E-28}
  DIR: {X:0.7071068 Y:0.7071068}
  NOR: {X:0.7071068 Y:0.7071068}
  DIR: {X:2 Y:1.586099E-28}
  NOR: {X:1 Y:7.930497E-29}
  DIR: {X:0.7071068 Y:0.7071068}
  NOR: {X:0.7071068 Y:0.7071068}
  </code></pre>
  
  <p>And the code to get this output (in Actor.cs):</p>
  
  <pre><code>        Trace.WriteLine("DIR: " + this.Direction);
  
          if (this.Direction.Length() &gt; 0f)
              this.Direction.Normalize();
  
          Trace.WriteLine("NOR: " + this.Direction);
  
          if(IsMoving)
              this.Position += this.Direction * this.Speed;
  </code></pre>
  
  <p>I don't understand why I'm moving in the same direction while my Direction vector is different each time. Can anyone explain this to me? </p>