Sign in to follow this  

how to correctly make a linear animation towards a target

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

This topic is 3375 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this