Advertisement

[Help] Javascript - function findEasyPath not working properly.

Started by July 25, 2022 11:49 PM
1 comment, last by joshLangley 2 years, 4 months ago

Hello,

I have a function that I want to quickly check the Manhattan path distances and make sure they are collision free. In my engine I do have A* but it's computationally expensive to do server-sided, and this algorithm is much faster if it actually worked. Basically any position the character is starting on, to the end position, there is two possible Manhattan paths it should check for, the x-axis first, then y-axis or vice versa. The problem I'm having is the function is returning the middle co-ordinate in-between the path coordinates, but the actual path it's taking is causing the character to move across the collision map when it should be blocking and disregarding that path. I'm sure it's because it is not actually properly following the path that it's checking. Does anyone know how I can fix the function so the middle coordinate returned is the proper path to follow that is being checked by the collision functions yf() and xf()? Any help would be appreciated I'm so stuck, I been doing desk checks but I'm getting confused.

Oh yeah it might help if I link to the code:

https://gist.github.com/Langerz82/4a23a78ab84662f249f033e3b7cd1e90#file-findeasypath-js

the code issue is here (I think).

https://gist.github.com/Langerz82/4a23a78ab84662f249f033e3b7cd1e90#file-findeasypath-js-L113

kind regards,Josh Langley.

Bad design and needed to simplify the problem I'll post my solution shortly.

UPDATE:

My new solution basically checks a pathing array against the collision map, and returns true or false, accordingly. Here it is if anyone is interested.

https://gist.github.com/Langerz82/32a9707b83bfd03dd5b041ab1f2309c6

kind regards,Josh Langley.

This topic is closed to new replies.

Advertisement