Original Post
Hello all, I am having some trouble with my 2D camera motion. I have the case of the jitters. The problem lies with the frame time, some code would explain it better:
/** Update the camera to another location if needed */
void Camera::Update(float dt)
{
Vector2f nextPosition;
if ( !m_pathToFollow.empty() )
{
nextPosition = m_pathToFollow.back();
if ( nextPosition.Equals(m_position, 0.1f) )
{
m_pathToFollow.pop_back();
}
}
else
{
nextPosition = m_dest; // will automatically go to the preset followed entity
}
m_velocity.Set( nextPosition - m_position );
m_velocity.Normalize();
// LOOK HERE:: m_friction is a scalar, and dt is the FrameTime
m_position = m_position + ( m_velocity * m_baseVel ) * m_friction * dt;
if ( m_cameraShake )
{
int vertdir = rand()/10000;
int hortdir = rand()/10000;
if ( vertdir >= 2 )
vertdir = -1;
if ( hortdir >= 2 )
hortdir = -1;
Vector2f shakeVelocity( vertdir, hortdir );
m_position = (m_position + (shakeVelocity * m_shakeIntensity) * dt);
}
}
So my question is, how do I make the camera motion frame independent without receiving the 'jitters'. Thanks, Tony S.