title: Simple physics-based movement
body: <p>I'm working on a 2D game where I'm trying to accelerate an object to a top speed using some basic physics code.</p>
  
  <p>Here's the pseudocode for it:</p>
  
  <pre><code>
  const float acceleration = 0.02f;
  const float friction     = 0.8f;  // value is always 0.0..1.0
        float velocity     = 0;
        float position     = 0;
  
  move()
  {
     velocity += acceleration;
     velocity *= friction;
     position += velocity;
  }
  </code></pre>
  
  <p>This is a very simplified approach that doesn't rely on mass or actual friction (the in-code friction is just a generic force acting against movement). It works well as the "velocity *= friction;" part keeps the velocity from going past a certain point. However, it's this top speed and its relationship to the acceleration and friction where I'm a bit lost.</p>
  
  <p>What I'd like to do is set a top speed, and the amount of time it takes to reach it, then use them to derive the acceleration and friction values. </p>
  
  <p>i.e.,</p>
  
  <pre><code>
  const float max_velocity = 2.0; 
  const int   ticks;       = 120; // If my game runs at 60 FPS, I'd like a 
                                  // moving object to reach max_velocity in 
                                  // exactly 2 seconds.
  const float acceleration = ?
  const float friction     = ?
  </code></pre>