# Camera woes

This topic is 4141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
Silly me, sorry to waste peoples time, after a little thinking I found the solution. Here is the code if anyone is inquiring:

    Vector2f destination( nextPosition - m_position );    m_velocity.Set( destination );    m_velocity.Normalize();        Vector2f moveTo( ( m_velocity * m_baseVel ) * m_friction * dt );    if ( moveTo.Length() > destination.Length() )    {        moveTo = destination;    }    m_position = m_position + moveTo;

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631773
• Total Posts
3002268
×