Here is my aproach:
// float orig[2], dest[2]; // [0] = x, [1] = y positions
// path calculation
if (dest[0] >= dest[1]) {
orig[0] += dest[0] / (dest[1] + (dest[0]-dest[1]));
orig[1] += dest[1] / dest[0];
} else {
orig[0] += dest[0] / dest[1];
orig[1] += dest[1] / (dest[0] + (dest[1] - dest[0]));
}
Is this approach clear enough and efficient in your opinion? The code isn't 100%, it's just a glimpse of the full code but this part is the juicy part !!
This code would be used to move a player by clicking on the ground where you want to move, like you see in games like baldurs gate for example.Try this program to see what the code does.