title: implement 2D gravity and basic collision C++ and OpenGL Tile based side scroller game
body: <p>I have some questions for correctly implementing a system that add gravity to my player while still detecting and correcting collision with the floor. I understand the basic math for the AABB and adding gravity vector to the players velocity vector then adding it to the position. For some reason when I try the player stops for the first few frames then eventually the velocity builds up to be more than the tile width and it goes through. I guess my real question is how to properly implement the gravity with the collision. Do I make gravity vector 0, 0 when it hits the floor or when I am just standing on the floor my collision detection will constantly move me out of the floor? I really don't know the flow of the logic with this situation.</p>
  
  <p>Edit 1:
  I am trying to make the simple engine myself to gain experience with programming. I kind of solved the one problem, I now can stop on the floor. My current logic is:
  add gravity to velocity, check for collision, adjust the velocity by the offset of the collision, if any, add velocity to the position then set velocity to 0.</p>
  
  <pre><code>m_velocity += m_gravity;
  
  glm::vec2 mtd = collideWithObject(objectVector);
  
  m_velocity -= mtd;
  
  m_position += m_velocity;
  
  m_velocity.x = 0.0f;
  m_velocity.y = 0.0f;
  </code></pre>
  
  <p>It works but I am not sure if that is the flow, I guess I just want to know what is the most common way to implement this.</p>