|
-
Oct 30th, 2002, 07:21 PM
#1
Thread Starter
Lively Member
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
-
Oct 30th, 2002, 07:29 PM
#2
Frenzied Member
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.
-
Oct 31st, 2002, 02:30 AM
#3
Addicted Member
I second that, however you don't even need the distance formula!
-
Oct 31st, 2002, 07:40 AM
#4
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|