Workshop.codes
Login
Create
kxtbit

True Dynamic Pathfinding

This code is over 6 months old. The code may have expired and might no longer function.

14 Comments

Log in or Sign up to leave a comment.
jtbfs almost 3 years ago

i've been wondering, how would this work for bots? i went to this a few times over the course of past few months, and each time, i tried to import it into a single bot (i just wnat it to go to the enemy with dynamic pathfinding), but i kept failing to understand the code, soo yeah..

kxtbit#1903 creator almost 3 years ago *

well, this system i made isn't as batteries-included as something like, say, OSTW's built-in pathfinding, where you pathfind directly on a dummy bot and the library does the rest of the work for you. instead, the way this pathfinding system works is by directly supplying a start and end position - in your case, the current position of the bot and the target position respectively - and it will output a list of positions representing each point in the path it found. from there, you'll need to make your own system to get the bot to walk to the first point of the path and then keep going to the next point when it reaches the first until it reaches the end. i might be able to hack together some OSTW code of that for you if you need help with that.

it's also worth noting that this system might not work well on more than a few bots at a time - dynamic A* pathfinding is REALLY taxing on the slow workshop servers and can already take quite a long time for just one bot, but more than one bot pathfinding long distances is definitely stretching it. additionally, because of OSTW's function semantics and the fact I chose not to make the pathfinder function a subroutine, the entire system will be inlined anywhere you use it, potentially making your element count explode if you use it more than once in your code.

jtbfs almost 3 years ago

but it'd be worth a try to see if i can import it into a bot, the only part i'm stuck on is... understanding your code 😭 you are so good that your code is too complicated for me to understand

kxtbit#1903 creator almost 3 years ago

the OSTW pathfinding requires you to make a pathmap beforehand, so it's not dynamic. using the pathfinder function shouldn't really require understanding the algorithm itself, since most of that stuff is kinda abstracted away. for a basic demo of a pathfinding bot, see this gist i made: https://gist.github.com/kxtbit/89a387411bcea10506f93f984717885d
the bot will spawn 10 seconds after you spawn, and you can press crouch + interact (ctrl + f on default bindings) to make the bot walk to you using dynamic pathfinding. it isn't perfect; the bot can sometimes get stuck forcing you to press the keybind again, and i sort of hacked this code together, but hopefully that can be helpful to show you how to implement my buggy pathfinding system into a gamemode if you wanted.

Naichiiiiii#2789 4 days ago

I'm a bit late lol but would it be possible to get a workshop code for this cause I don't use OSTW and I'd love to try it for myself

jtbfs almost 3 years ago

thank you so much for the reply! i see, i kinda figured that out. but i did not know OSTW has its built in pathfinding? but is it dynamic? the only true dynamic pathfinding i could find was this one ^^

DaddyChill over 3 years ago

Bro, i gotta commend you, this is awesome. So simple, clean, and FAST.

We should collab some day. I made a zombie game concept, but after the OW2 update, it messed up bots path finding. Maybe we can work together in fixing the game. Check out my game and let me know what you think.

Code: GWRH3 (Zombie Robots)

HuKuTa94 about 4 years ago *

Nice idea. One more implementation of the pathfinding in workshops. Sometimes it works stranger but I think it fixable.
https://i.postimg.cc/zX75jdQj/image.jpg

If it will low-required performance for a lot number of bot this tool can become very useful and low cost for PvE mod developers.

I develop the path-node-builder mod, but it required store some data for usage by bots. Here the code: QRD5A

Your idea is pick around walkable positions with some step (for ex. 0.5 meters) and apply A* algorithm to find the closest position to the target? Or does it works a little bit complexity?

kxtbit#1903 creator about 4 years ago *

the thing with the going through walls and floors i'm not entirely sure of. it's probably an issue with the path refiner (tries to remove unnecessary points in resulting paths). my best guess is that server-side raycasts are done on a simplified version of the map geometry that may not have entirely correct collision. it seems far fetched but it's my best guess, because i'm fairly sure that i coded my collision checks correctly. if this happens a lot, which it can on some maps, it can sometimes help to disable the path refiner, maybe i should make a workshop setting for that. EDIT: done

also, it doesn't use walkable positions. what it actually does is when it selects the neighbors of the grid nodes, it does a line of sight check to the neighbor direction plus 0.25Y. if this succeeds, then it chooses the position of a raycast pointing down from the position that was previously checked as the position for that node on the grid. i should note that line-of-sight checks are done with raycasts instead of Is In Line Of Sight because it seemed to be more accurate.

also, about the performance - the test code that i put here (not the github library version) has the default wait threshold set to 12. it is pretty fast but it also essentially consumes the entire server capacity while pathfinding. however, setting it to 5 will in my experience, decrease the server load to the point where it will not usually go over 100, so pretty good performance. in addition, the debug mode version is not good for gauging the performance, because creating the orange spheres generates a ton of extra server load, so the wait threshold is set to 3 instead of 12 in the debug version, so keep that in mind.

Spade#12107 about 4 years ago

How

kxtbit#1903 creator about 4 years ago *

it basically does A* pathfinding along a 2D grid that's overlayed over the 3D space - that is, one position in 2D space could correspond to 2 or more grid positions, to account for the 3Dness of the real environment. it also has a sort of debug mode that can be enabled to show all of the grid cells that are explored by the algorithm, but it's not included in this gamemode - let me know if you want to have the debug code so you can see it more in depth

Spade#12107 about 4 years ago

sure

kxtbit#1903 creator about 4 years ago *

KQBEH
here, this code is for the debug mode version
all of the nodes generated by the algorithm will appear as orange spheres
if the spheres are disappearing, it's because there's a limit to the amount of orange spheres that can be visible at once (to not go over the workshop effects limit), so it has to remove older ones, and that's why they disappear

Spade#12107 about 4 years ago

big

Workshop.codes