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

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

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 on other sites
 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 on other sites
Or just use some simple physics equations.

velocity += acceleration * elapsedTime;
position += velocity * elapsedTime;

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.

1. 1
2. 2
Rutin
22
3. 3
4. 4
khawk
14
5. 5

• 13
• 26
• 10
• 11
• 44
• Forum Statistics

• Total Topics
633743
• Total Posts
3013643
×