Results 1 to 4 of 4

Thread: stupid thing I cant work out

  1. #1

    Thread Starter
    Lively Member FireSlash518's Avatar
    Join Date
    Nov 2001
    Posts
    67

    Talking stupid thing I cant work out

    I must be totally retarded...


    I have two points, X1, Y1, the starting coords, and X2, Y2, the end coords. If i want to move the position of an object from start to end at a fixed speed (S), how would I do this?

    Im thinking maybe I need to go back and take geometry again

    Leader of the Maxoverkill Mods
    -Fire§lash

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Code:
    Init:
    dist = sqrt((end_x - start_x)^2 + (end_y - start_y)^2)
    time = (dist / speed)
    start_time = CurrentTime
    UpdateIteration:
    progress_time = CurrentTime() - start_time
    lerp_progress = (progress_time / time) * GlobalSpeed
    if abs(1.0-lerp_progress) < 0.05 stop
    current_x = start_x + (lerp_progress * (end_x - start_x))
    current_y = start_y + (lerp_progress * (end_y - start_y))
    Essentially, find the time it will take to arrive at the destination, given the speed, and start and end coordinates. Then, at each iteration, find how much time has passed since you started moving, and the percent of the move that is complete. Then simply compute the current position through linear interpolation.

    Z.

  3. #3
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    I second that, however you don't even need the distance formula!

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    No, but then you cannot use the interpolation method. You could construct a vector for direction, and move along that vector, until you are close to the end point, but in that case you still have to evaluate the distance, except you do it once per iteration.

    Z.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width