Jump to content
  • Advertisement
Sign in to follow this  
Headkaze

Some questions about animation

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!