/// <summary> /// Update according to Gametime /// </summary> public override void Update(GameTime gameTime) { // No active behavior does not mean no mouvement // but in case of a demo is much easier if (!Active || !Behavior.HasActiveBehavior()) { return; } double timeElapsed = gameTime.ElapsedGameTime.TotalSeconds; // Wander need time elapsed to be time independant Vector2 steeringForce = Behavior.Calculate(timeElapsed); // Get acceleration using steering forces Vector2 acceleration = Vector2.Divide(steeringForce, Mass); // Update velocity using acceleration Velocity += Vector2.Multiply(acceleration, (float)timeElapsed); // Trim back velocity using extension method Velocity = Velocity.TruncateExt(MaxSpeed); // To avoid stange behavior when agent arrive // update only if velocity is not too close to 0 if (Velocity.LengthSquared() > 0.00000001) { // Update internal values UpdateOrientation(); UpdateLocalBase(); } // Update position Pos += Vector2.Multiply(Velocity, (float)timeElapsed); // Make world toroidal WrapAround(_world.GraphicsDevice.Viewport.Bounds); }