Hello
I need help with understanding how to approach the logic of this.
So i have an array of points which my sprite will follow at a fixed speed the array looks like this:
[
{"X":"2" ,"Y":"2"},
{"X":"9" ,"Y":"2"},
{"X":"10" ,"Y":"3"},
{"X":"1" ,"Y":"3"}
]
My grids are 50 by 50 pixels and my sprite moves at 4 pixels per second.
Now I set up my sprite info so i have and i can calculate the line the sprite will take quite easily:
sprite.currentLocationX = path[0].X * 50;
sprite.currentLocationY = path[0].Y * 50;
sprite.dX = path[1].X * 50; //destination Xsprite.dY = path[1].Y * 50; //destination Y
My question is how do you calculate when the sprite has passed destination X:Y and so update the sprite's destination ?
I update the sprite's X:Y current location every frame using delta*speed.
I thought about using the idea of checking when X:Y is greater than destination X:Y but that merely assumes the sprite is moving north east only.
If it matters in terms of explaining the way to work it out, my sprites moving in 8 compass directions.