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

## Recommended Posts

I have a basic animation system in a game I'm working on. The main movement code looks like this

m_alpha += m_delta; m_alpha = MIN(m_alpha, 1.0f); m_x = m_startX + m_alpha * (m_endX - m_startX); m_y = m_startY + m_alpha * (m_endY - m_startY); m_z = m_startZ + m_alpha * (m_endZ - m_startZ);

Currently m_delta is a fixed value. I need to change it to be based on a m_speed (acceleration) value that is relative to elapsedTime. So I assume this is as simple as

delta = speed * elapsedTime;

But not only do I need the movement to be relative to elapsedTime, so it is framerate independant, I also need the movement to be relative to the distance from m_start to m_end. So the farther the distance to travel the quicker it will move and the shorter the distance the slower it will move. In other words the time it takes the object to get from m_start to m_end is the same no matter what the distance.

##### Share on other sites
To start, you need to define a time duration value to test your alpha against to produce your fraction to apply to the movement.

ex: regardless of distance... it needs to move from a to b in "timelimit" ms.

delta doesn't need to use speed * elapsed time

you simply need to accumulate your elapsed time into alpha then test (divide) alpha against "timelimit" to produce a fraction. the movement math x, y, z can then remain mostly the same.

m_alpha += elapsed time;

m_frac = malpha/m_animationtimelimit;

m_frac = min(m_frac, 1.0f);

movement code should use m_frac instead of m_alpha.

if you need to restart it, 0 out m_alpha and it should begin anew.

• 10
• 18
• 14
• 18
• 15