i have a mathematical problem:
i have a function where the only parameter is the current time. the return should be a position which is used to place an object on a certain place.
int position(int time)
{
int x = 0; //TODO implement x depending on time
return x;
}
so basically the function is called every frame to put the object in motion.
the motion should look like this (this is the actual question):
thanks!
edit: ok in other words: imagine a car that drives at constant speed for A minutes and then stops for B minutes. then drives again for A minutes and stops again for B minutes.
where is the car at time X?
OK, if I understand correctly:
int position(int time)
{
int count_of_AB_cycles = time / (A + B);
int time_in_current_cycle = time % (A + B);
int time_moved_this_cycle = (time_in_current_cycle < A) ? time_in_current_cycle : A;
int total_time_moving = (count_of_AB_cycles * A) + time_moved_this_cycle;
return total_time_moving * speed;
}
assuming integer division, etc - you'll need floor()
s if A and B are non-integers etc.