SHARE
TWEET

Moving in direction

a guest Sep 2nd, 2011 60 Never
  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. }
RAW Paste Data
Top