Jump to content
  • Advertisement
Sign in to follow this  
ehmdjii

how to correctly make a linear animation towards a target

This topic is 3658 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

hello, i want to have an object move towards a position in 3D space and stop exactly at that position. so what i do is, each frame i set the new position of the object along the direction-vector to the target multiplied by it's speed and the duration of the last frame. once it is near enough to the target (below a certain epsilon), the animation stops. this approach seems to have two problems: 1. if the framerate is very low, it is possible, that the animated object "overshoots" the destination. 2. if the animation stops, the object is probably not at the very exact position, but rather somewhere in between the epsilon. i could of course just set the position to the destination if the object is in this epsilon, but that leads to a jump if the epsilon is large and/or the speed is slow. i think if problem 1 is solved, problem 2 will solve automatically. thanks for any help on these issues!

Share this post


Link to post
Share on other sites
Advertisement
If the animation starts at t0, and the distance from the start position to the target position is D, and the speed of the object should be v, then the target position is reached exactly at
t0 + T where T := D / v

Now, the video framerate will in general not allow you to hit t0 + T exactly. Instead, you need to render the frame at ticks
t0, t1, t2, ..., tn up to tn <= t0 + T and tn+1 > t0 + T

The corresponding positions are
p(t) := p0 + v * ( t - t0 )
where p0 denotes the start position, and v the velocity vector computed like you've said in the OP, until t0 + T is exceeded. If it is exceeded, then you use the target position as is.

Notice please that this method computes the positions due to the actual time moment, and not due to the duration of the last recent video frame. So it adapts to the current frame rate without looking into the history of motion.

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!