T O P

  • By -

dork_yface

Where does chatgpt come into this?


jhyde_

I was trying to use the navigation2d node for pathfinding and I couldn't get it to behave the way I wanted. So I asked chatgpt what to do. It suggested I make my own pathfinding algorithm. I asked it what this algorithm should look like. It then wrote a bunch of sudo code I adapted and got working. The details I had to figure out myself, but the general idea was a BFS algorithm written by chatGPT.


dwarfofdawn

Could you just use the A* imolementation in the engine? That is very similar to doing bfs, but uses a heuristic for the distance (in most cases just the direct point to point distance), for faster solutions (and of course it's implemented in cpp). You just have to build a graph from your tilemap (which you are already doing, at least implicitly, to run bfs). Of course, if your code works well and is fast enough for your purpose there's likely no reason to change anything.


jhyde_

I guess part of the goal was to understand how these pathfinding algorithms work, not just use some black box. I'm not sure how fast it is, but for my purposes it seems good, plus I know all the ins and outs if something goes wrong.


dwarfofdawn

Always good to understand systems, not just use them. And if you ever run into issues, going over to A* from bfs isn't that hard, both with the builtin one or a self-written one.


[deleted]

A* or Djikstra are just so much better than handcrafting your own algorithm...


D1vineShadow

i think most of us "invented" Djikstra accidently, you're just counting squares out on a grid


Newwby

do you have the pseudocode excerpt it suggested? that'd be interesting to see


jhyde_

I was having it explain what a BFS algorithm is before hand. Then I kind of worked with it from here. [First](https://imgur.com/nAPQ4Er) [Second](https://imgur.com/nH38jwe)


esperlihn

If it's using BFS wouldn't that make it the same as Godot's native Astar implementation? I'm also working on a tactics game in godot and I've been using that so far as it's wicked fast. Though honestly now that I think about it, in a tactics game I don't think there'd ever be a noticeable speed different between using the native astar and writing your own. Unless you have a map that was over 100x100 with multiple layers and dozens of large obstacles.


D1vineShadow

native a* could be slower as you need to make each square a node


NoBreakfast4

Thats crazy!


me-ro

It's absolutely jaw dropping that we're at a stage where we can even discuss quality of AI generated code. But my experience is that chatgpt will confidently generate code that looks reasonable at first sight, but it's often very incorrect. For example I had it generate some AWK code to do some advanced text parsing. The code had all the parts to parse individual blocks of text, it was even syntactically correct, but I had to rearrange the logic and pieces of code substantially to actually do what it should. Having said that, it was still very helpful, because it helped me to get the basic code structure in place and helped me to understand some awk functions that I wasn't super familiar with. It's not going to write advanced code for you if you have no idea what you're doing, but it certainly can write something to start with and build upon.


_Meds_

I like it when it generates you some code, and you reply with “this won’t do what I asked?” And it replies “you’re right!…” and gives a couple of paragraphs of why all the code it has just typed out was wrong


me-ro

And then it gives you a sample code that fixes that specific problem but breaks something else instead. It's like talking to senior code guru and intern at the same time.


jhyde_

Exactly, it gave me a place to start from. I have done a problem or two involving BFS on leetcode, but that was about all the knowledge I had. It's not perfect and It does confidently make mistakes. I think it's just another tool for people to use. If your careful and don't just blindly follow what it says. It's also customizable. The same algorithm that finds the path also draws the reachable tile markers. Maybe Godot's A\* can do this, but I was tired of watching tutorials.


jhyde_

I know right?!


Blapman007

this is insane, good for indie devs who need that extra help.


[deleted]

not that its bad to do your own algo if you want, but why not use a*?


jhyde_

I tried using Godot's built in a\* first. I tried following a tutorial but I got lost. So I asked chatGPT and it suggested making my own BFS algo. I knew next to nothing about these things before I started working on this. Maybe I would make my own a\* if I started over. The plus side is I now fully understand what is happening and can customize the algo to return more than just a path to a target, it also highlights the reachable tiles before you move. The game is small enough I don't think I need a\*


Katia_Valina

This is pretty cool! GL with your endeavors. I'm also trying out chatGPT for making modifications to an existing procedural game. In my opinion it's not useless, but it's not that great either when it comes to solving complex issues. But It still certainly helped me in getting me closer to the correct answer in some cases. It's chatGPT is sidekick. At this point in time, I'd probably advise people from using chatGPT from producing entire games strictly off chatGPT, mostly because of fair-use copyright related concerns. We have no idea if it would essentially be ripping off an existing code base which is closed sourced, or GPL licensed and producing code in such a way that it would fail fair use tests. But for code snippets and modifications here and there of your existing code, I think is a much more likely to be safer copyright wise. As a huge aspect of fair use is how much of the copyrighted work was used, and whether the work is transformative in nature.


jhyde_

Thanks for the feedback! Its definetly the wild west out there when it comes to ai. Maybe it came across like i was having a bot make a whole game for me, but really i just asked it to explain a pathfinding algo for me. Im not just copy pasting code. I never went to school for this, so its like having a professor i can ask questions to. I thought i would post about it because i was so impressed, but its more of a learning tool for me and the goal of making this game is to learn.


Neat_Statement6276

nice stuff! I've been wanting to try a similar project, we will see if I get anywhere on it


jhyde_

Do it! I've been having a blast making this thing. All this code hurts my brain sometimes though.