• Advertisement

Archived

This topic is now archived and is closed to further replies.

Point to Point Sprite Motion

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

Hey, Is there an easy way or a DirectX function to move a sprite from a certain point x1,y1 to x2,y2 without using trig functions or square roots after every frame? Like in Diablo where you click a point and the character walks in a straight line. What is the most effecient way to accomplish this? VK

Share this post


Link to post
Share on other sites
Advertisement
no need for trig at all -

say you want to move from x1 to x2 in T seconds/frames/whatever, so... Vx (the x velocity) = (x2 - x1)/T this is computed only once in the animation. Now, at every second/frame/whatever:

x += Vx (until x = x2) and
y += Vy

Of course, you may have to get a little more complex to account for fractional times, rounding errors, etc. But the point is that you don''t need trig anywhere in the algorithm at all.

Share this post


Link to post
Share on other sites
Not exactly what you are looking for but a little trick that can be used for certain effects...

Assume you have a sprite ''mySprite'' and you wish to move it to the position ''dest'' on the screen.

mySprite->xPos -= (mySprite->xPos - dest->xPos) / step;
mySprite->yPos -= (mySprite->yPos - dest->yPos) / step;

This produces movement such that the sprite decelerates as it moves towards the destination point. The higher the value of ''step'' the more time it takes to reach the destination point.

Cheers,
Sharky


Share this post


Link to post
Share on other sites

  • Advertisement