How to determine where on a path my object will be at a given point in time?
- by Dave
I have map and an obj that is meant to move from start to end in X amount of time.
The movements are all straight lines, as curves are beyond my ability at the moment. So I am trying to get the object to move from these points, but along the way there are way points which keep it on a given path.
The speed of the object is determined by how long it will take to get from start to end (based on X).
This is what i have so far:
//get_now() returns seconds since epoch
var timepassed = get_now() - myObj[id].start; //seconds since epoch for departure
var timeleft = myObj[id].end - get_now(); //seconds since epoch for arrival
var journey_time = 60; //this means 60 minutes total journey time
var array = [[650,250]]; //way points along the straight paths
if(step == 0 || step =< array.length){
var destinationx = array[step][0];
var destinationy = array[step][1];
}else if( step == array.length){
var destinationx = 250;
var destinationy = 100;
} else {
var destinationx = myObj[id].startx;
var destinationy = myObj[id].starty;
}
step++;
When the user logs in at any given time, the object needs to be drawn in the correct place of the path, almost as if its been travelling along the path whilst the user has not been at the PC with the available information i have above.
How do I do this?
Note: The camera angle in the game is a birds eye view so its a straight forward X:Y rather than isometric angles.