Hi everyone!
I come with a general question however I've also tried to solve it and failed. Not miserably - it half works....
Anyway, after some sort of path finding algorithm has been executed and we're left with an array containing path nodes, how do we move a player along that path inside a game loop? I've attempted to research this and have fallen short so, instead, I gave it try.
Please see this CODE PEN with my efforts (left click on the canvas to find a path). The path finding is being done with QIAO's pathfinding.js and works really well! I'm quite happy with it.
You'll see the start of the path finding code around line 276 in the code pen JS window. The part where I'm trying to move the player begins at line 313.
There are 2 major problems with it:
- The player will move up and/or left but not down and/or right. I have a suspicion that it has something to do with the fact that positions are based off of the top left corner and I haven't taken this into account. I did think of this and tried to fix it by working with the player's center and the node ending center.. to no avail.
- For some reason the player's speed is completely ignored. You can set the player's speed on line 122. Doesn't matter if it's 1 or 20, he still moves to the destination (as long as it's up and/or left) at the same speed. This isn't good.
NOTE: If I set the player speed to 20 it actually seems to fix the issue stated in #1...
Anyway, if anyone can help, it would be very much appreciated. I tried to strip out as much unnecessary code as possible.
Thanks,
SD