Basically, once the path is generated, the list of coordinate to go through is stored in an array you can query via getCtXPathList(n) and getCtYPathList(n), n is just the index of the cells listed. It goes from 0 (starting cell) to the the number of cell to travel-1 (the last cell).
But it's just coordinates, if you simply read the array and change the position of the sprite accordingly, you will have a stepped movement.
Lerp(a,b,t) = a + (b-a) * t
so basically if t evolve from 0 to 1 you get a nice interpolation from a to b.
Here I use lerp() to go from index n (a) to index n+1 (b) in the array.
The global variable iteration simply count time since the start of the interpolation.
t = iteration-floor(iteration) means that I only keep the decimal part.
t = 5.2 - floor(5.2) = 5.2-5 = 0.2
So for example, if you are at iteration = 5.5 seconds
You will get something like
Which means you'll be halfway between the X coordinate at n=4 and n=5.
Which also means that if you choose the cut corner option, you'll go faster in diagonal than in orthogonal movements.
This formula can be enhanced by taking into account the distance. But it should be handle at the 'iteration' incrementation. With something like
- Code: Select all
set length to distance(getCtXPathList(max(0,floor(iteration)-1)),getCtYPathList(max(0,floor(iteration)-1)),getCtXPathList(floor(iteration)),getCtYPathList(floor(iteration)))
set iteration to (length > 0) ? dt*Speed/length : 0
Well, as there was still some mistake in my capx, I updated it with these new formula and some comments.
And I added a debug text you can set to visible to see how some of the values evolve.kyat-PF.capx