Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Moving in direction

By: a guest on Sep 2nd, 2011  |  syntax: C#  |  size: 0.35 KB  |  hits: 56  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. double x;
  2. double y;
  3. double angle;    // in radians, if you want degrees: convert to radians before use
  4. const double movementSpeedPerSec = 10.0;
  5. ...
  6. Update(GameTime gameTime)
  7. {
  8.         x += movementSpeedPerSec * cos(angle) * gameTime.ElapsedGameTime.TotalSeconds;
  9.         y += movementSpeedPerSec * -sin(angle) * gameTime.ElapsedGameTime.TotalSeconds;
  10. }