• A* Pathfinding Module
    67 replies, posted
  • Nice but... whatever happened to that "industry leading AI" thing all Source games supposedly already have? Can't NPCs already find their way around maps that have their nodes made out?
  • What kind of lua created NPCs can there be that can't simply inherit from an existing Source NPC? You shouldn't be having to reinvent the wheel here.
  • [QUOTE=DaddyWarbox]What kind of lua created NPCs can there be that can't simply inherit from an existing Source NPC? You shouldn't be having to reinvent the wheel here.[/QUOTE] There are uses for it outside of NPCs. I didn't create it because I felt I had to, I did because I wanted to.
  • Avatar of tad2020
  • [QUOTE=Jinto]There are uses for it outside of NPCs. I didn't create it because I felt I had to, I did because I wanted to.[/QUOTE] I could see this being used to make some cool laser weapon effect, like from some animes where the beams will bend around obstacles instead of going thought them.
  • Avatar of Skurmedel
  • [QUOTE=DaddyWarbox]What kind of lua created NPCs can there be that can't simply inherit from an existing Source NPC? You shouldn't be having to reinvent the wheel here.[/QUOTE] Yes in the case of NPCs you will. Let's say you wanna script an murderous box, in that case, creating a npc_rebel (for example) and setting his model to a box and a bunch of other stuff isn't really the optimal way of doing it. That NPC is made to behave like a rebel, which probably will do, unless you set a shitload of modifiers, and that will probably still present problems. If you had the real sourcecode you could easily derive the base NPC, add stuff to it and more or less there wouldn't be a limit to what you could do. But we just have Lua and the NPCs that are already there doesn't work in every scenario.
  • [QUOTE=Skurmedel]Yes in the case of NPCs you will. Let's say you wanna script an murderous box, in that case, creating a npc_rebel (for example) and setting his model to a box and a bunch of other stuff isn't really the optimal way of doing it. That NPC is made to behave like a rebel, which probably will do, unless you set a shitload of modifiers, and that will probably still present problems. If you had the real sourcecode you could easily derive the base NPC, add stuff to it and more or less there wouldn't be a limit to what you could do. But we just have Lua and the NPCs that are already there doesn't work in every scenario.[/QUOTE] Hasn't garry added scripted NPCs yet?
  • Avatar of Skurmedel
  • No, and even if he had done so, what would you do if you wanted to do your own pathfinding. This is for pathfinding, it could be used for missiles, evil cars, animated cereal and whatnot. NCPs isn't the only use for it.
  • [QUOTE=Skurmedel]No, and even if he had done so, what would you do if you wanted to do your own pathfinding. This is for pathfinding, it could be used for missiles, evil cars, animated cereal and whatnot. NCPs isn't the only use for it.[/QUOTE] He should have been able to hook the engine's NPC code for that stuff easily enough. I still think doing it all in lua is reinventing the wheel (and costs more having to run through the lua interpreter besides).
  • Avatar of LifeForm
  • This woud be usful for that new zombie mod that's coming up where zombies are supposed to track down players and kill them.
  • Avatar of Skurmedel
  • [QUOTE=DaddyWarbox]He should have been able to hook the engine's NPC code for that stuff easily enough. I still think doing it all in lua is reinventing the wheel (and costs more having to run through the lua interpreter besides).[/QUOTE] How would he do that, bribe Garry for source access?
  • Avatar of Arbitration
  • Excellent work Jinto. Wait what the fuck, Here I thought I was in for a tasty new treat, Turns out I get ancient threads dug up from the grave.
  • Avatar of Nev
  • [QUOTE=lilezek;16169037]Could someone reupload this script?[/QUOTE] There you go.. [url]http://code.overvprojects.nl/viewcode.php?id=261[/url]
  • Avatar of lilezek
  • [QUOTE=Nevec;16170086]There you go.. [url]http://code.overvprojects.nl/viewcode.php?id=261[/url][/QUOTE] Thanks.
  • Avatar of mastersrp
  • Once again, Jinto makes something awesome for the gmod lua! GREAT Job, it'll be VERY useful in the future, if anyone gets themselves together to do stuff with this.. I'm no lua coder myself, i've tried a few things, but i'm not really into it. [editline]04:46PM[/editline] i fail for not realizing the date of this. It's been done before, i KNEW it was a bit familiar..
  • Avatar of Deco Da Man
  • This is kinda old.. if it doesn't work or you're looking for something a bit more dynamic when it comes to pathfinding, try my module: [url]http://wiki.garrysmod.com/?title=A-Star_Pathfinding_Module[/url]
  • Avatar of Termy58
  • [QUOTE=Deco Da Man;16238375]This is kinda old.. if it doesn't work or you're looking for something a bit more dynamic when it comes to pathfinding, try my module: [url]http://wiki.garrysmod.com/?title=A-Star_Pathfinding_Module[/url][/QUOTE] How is it faster and more efficient it looks messy as hell and unoptimized, jinto's was way more dynamic. Yours is just shortest a to b.
  • Avatar of Deco Da Man
  • [QUOTE=Termy58;16360432]How is it faster and more efficient[/QUOTE] If you'd take a look at the source code of my module, you'd see that I minimize unnecessary calls, having all the code in one function, and use of memory, this includes not using useless locals. In fact, swap line 34 and 35, and merge the local definition in with the definition now on line 34. Jinto has a more OO style in his, while mine is more low-level. The things he uses, including use of metatables, costs him a decent amount of speed. I aimed for speed with mine. You may say 'but metatables cost shit all speed'. True, however they are more expensive than how I do it, and I aimed for mine to be as fast as possible, while still maintaining it's dynamism. The reason I aim for absolute speed, is that the application I made it for required it to be so. This module was not intended for use in GMod, however I made it in a way that allows it to be used in any Lua situation. The application I was making was a simple RTS engine. I was experimenting with how to handle masses of units in an RTS engine. I found that my shoddy pathfinding was the real culprit when it came to slowing my application down, so I made the A* module which you see today. After I began using it, my application was so much faster. If you were to make an RTS engine, such as one that used in AoE or Empire Earth, you would understand the need for absolute speed, and the need for complete control in the pathfinding process. [QUOTE=Termy58;16360432] it looks messy as hell [/QUOTE] I admit that my coding stile is quite cluttered, and some people may disapprove of it, but I like my coding style and will continue to code in it. I like it, I find it easy to read. [QUOTE=Termy58;16360432] and unoptimized [/QUOTE] How so? [QUOTE=Termy58;16360432] , jinto's was way more dynamic. [/QUOTE] Jinto's was more handy than dynamic. It did what most GMod programmers would want to do, and that is to find the shortest clear path in a waypoint system. Jinto provides utilities that simplify the finding of this path, and even kindly provides tracing functions to help. Mine, however, offers dynamism and flexibility. With the multiple stages in which callbacks provided are called, the coder has complete control at every main stage throughout the process. When I use the word flexibility, I'm not simply using the word cause it sounds cool, I'm using it as my module can be adapted to any system (e.g tiles, hexagonal tiles, waypoint system (like source, and Jintos), anything!) with minimal sacrifice when it comes to the speed of and the control the coder has over the path finding process. [QUOTE=Termy58;16360432]Yours is just shortest a to b.[/QUOTE] This is just a silly statement on your behalf. Jinto's is simply "shortest a to b". In fact, Jinto's is just "shortest a to b in a waypoint-based system". Mine is "path from a to b that suits coder's need". If you wanted to consider, for example, lava that injured an NPC in Jinto's system, you'd have to override the heuristic function, which is not easy, as the Node table is local. You would have to recode Jinto's module to be suit your needs. I'm pretty sure that most coders, me included, would want to keep their code that states what path is best in the piece of code that launches the path find. My A* module gives the coder absolute control over how each node is considered in the process. You may not want to use my module. If you don't I don't really care. I released it as I thought someone else out there may be able to use it.
  • Avatar of GreyIOutcast
  • Deco Da Man, your module would give an error. [lua]and table.call(walkable_checks, current_node, neighbour_node, startinging_node, target_node, heuristic, ...) -- ...or unwalkable...[/lua] That's a direct paste from your codepad of it on the Gmod Wiki. There is no such thing as "startinging_node". Obviously, your module isn't ready for use yet.
  • Avatar of Deco Da Man
  • [QUOTE=GreyIOutcast;16552854]Deco Da Man, your module would give an error. [lua]and table.call(walkable_checks, current_node, neighbour_node, startinging_node, target_node, heuristic, ...) -- ...or unwalkable...[/lua] That's a direct paste from your codepad of it on the Gmod Wiki. There is no such thing as "startinging_node". Obviously, your module isn't ready for use yet.[/QUOTE] Did a Find+Replace for 'start' in the latest version and didn't bother to test it. Thanks for spotting that :)
  • Avatar of GreyIOutcast
  • [QUOTE=Deco Da Man;16557408]Did a Find+Replace for 'start' in the latest version and didn't bother to test it. Thanks for spotting that :)[/QUOTE] No problem. I suggest you update the link on the gmod.com wiki. I'm in the middle of trying to make a pathfinding application (First I've got to set up a node graph, though) for the gamemode "Gmod TD" Would be a lot better if you could build mazes for the enemies, so I'm trying to do so. :v: I think I may try yours first, if it's all working. After that I'll switch over to Jinto's to see how his works as well, since I have both.
  • Has anyone made an simple addor for this? Something like Add Path tool or spawn them as entity.
  • Avatar of Prefan
  • Sorry for the massive bump, but can someone upload Jinto's astar module again? I can't find it searching around. Deco's module confuses the hell out of me, I can't make sense of it.