Jump to content
  • Advertisement
Sign in to follow this  
ajm113

Animating a "object" Moving Point A to Point B?

This topic is 2298 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 was wondering if someone can tell me the most effective way on creating a "mover" sorta system? Just like games use to create lifts, elevators or moving objects?

So far my movers have the "jittering" effect from the if statements that I was using not taking into account the game delta variable. So if the value is even .1 over the goal coordinates, it would jump the object back and forth creating the very ugly effect.

I was thinking something like this could work...


if(object.X < goal.X)
object.X += 0.1 * gameDelta;
else
object.X -= 0.1 * gameDelta;

dist = getDistance(object, goal)

if(dist <= 0.5)
{
object = goal;
}


I was wondering if someone could write example on how to move a object properly to it's X and Y destination that doesn't get that ugly effect? My method kinda feels unprofessional.

Share this post


Link to post
Share on other sites
Advertisement
double distance = getDistance(object, goal);
if (distance > speed_per_frame)
object += (goal - object) * (speed_per_frame / distance);
else {
object = goal;
// perhaps trigger something here
}


Something like that should do.

Share this post


Link to post
Share on other sites
The distance moved by the object per frame should be a factor of both X and Y. For example, if the goal position is (15, 18), then the movement speed should be 1 or 3. That should eliminate the jitter effect.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!