Devlog 3
This week was mainly spent getting things ready to be completely implemented and working - and well this week too as of writing has also been spent on getting everything implemented. The main two things implemented were AI and doors, as well as some fixes and art.
AI
AI in this case is actually very simple, I only have to calculate the lowest count of nodes to a certain location. I could use A* if I wanted a weighted node graph - but that's not really necessary thankfully. The first attempt I made was using a binary tree (and it might already be obvious for two reasons why this doesn't work), where each node has 2 references to other nodes, alongside an ID so we can easily tell which node to search from and to. Typically for a binary tree we also use references to other nodes, but since C# doesn't really have similar pointer logic to C++, it's easier to just have a list and index references. After we create a binary tree from the nodes we can use it to search. However - there's already a big problem. Binary lists don't go backwards, and I didn't realise that until I got a stack overflow error. Weirdly, this is the first time I've ever seen a stack overflow error, but the easy solution for this is to just make sure I check that I haven't already checked a node.

(Unity doesn't happen to like this happening - it just spams this forever, even after the issue was fixed.)
To quickly explain the binary tree search algorithm, there's a list of indices, and a recursive function. Each time it recurses, it adds the current search index to this list, and if it's the expected value, we return there. If not, we search the children, which use the same function to check their children and so on. If the expected value doesn't exist in the children, we can just remove the last index from the list. I also of course have to check the list before adding the index to make sure it's not already in there, and if it is, we return false. However, there's another problem - some nodes need more connections. I can use the same algorithm though, although I need to rewrite the code. We should also run this as an async function, even if it's unlikely to cause a significant performance hit.

(and here's the finished code! It's relatively simple - and there might be thread problems depending on how Unity handles callbacks. Hopefully not. Multithreading is not something I'm comfortable with.)
This thankfully works exactly as expected, and the NPC can simply want to go somewhere, follow the nodes, and switch to the layer of the nodes to handle different rooms. It's relatively simple to build behavior around this system, which is what I need to do next.
Doors
Doors were a little annoying - mainly because in retrospect some of these ideas may have not been the optimal ways to implement this. However, they work, and they're easy to add.
(example of one of these doors!)
We need to consider the layers so we can switch the z transformation to bring objects in and out of view. We also need to change the player layer, which is attached to a player class function. The backing colour is important so I don't have to add borders, except if I want a solid colour background. Realistically this isn't necessary - but it is easy. There's also an is_following tag, as I don't really need complicated camera control. It's simple - however I ran into an issue where it picked up the door as the object on the layer. This is a bug anyway, but for now I added an ignore tag, and just skipped over entities with that tag when finding the room to transform. Convoluted, but it works. For now.
What's next?
Over the next days, I need to quickly implement the last bits of the gameplay. I've set myself up to quickly implement everything else, and hopefully I can get something working. Inventory, dialogue, NPCs, logic, etc., shouldn't be as hard as it seems it should be to implement.
Files
Lilies in Autumn Bloom
More posts
- Documentation (Final Devlog)22 days ago
- Devlog 522 days ago
- Devlog 436 days ago
- Devlog 250 days ago
- Devlog 153 days ago
- Game Concept Devlog73 days ago
Leave a comment
Log in with itch.io to leave a comment.