The quest to reactivate my brain – Day 3
As expected, it got late. I got home at around 9pm yesterday and I was completely out of food. So the choice was between rushing to the store to cook something or working on the game. So naturally I fired up Unity.
I took a good look at my approach to collision detection and decided it was quickly becoming too “hacky”. For every small problem I tried to avoid, another was popping up. I decided to – again- remove half the code and try something different. Maybe I could avoid collision altogether if I implemented proper pathfinding first? While researching I found the fantastic A* pathfinding project by Aron Granberg, which made a few things much more elegant. I added a Plane behind the 2D scene where I do the pathfinding. The result is a Vector3() array, which awesomely enough is the data structure that iTween uses as a path. So I let the A* algorithm do its thing, call iTween.PutOnPath with the result and let the character move. That will eventually avoid collisions entirely. I say “eventually” because it doesn’t work quite right yet.
In theory, the box around the counter would tell the A* algorithm that the nodes inside it are not walkable, so the pathfinding should navigate around that. It doesn’t. After tinkering with it until about midnight, the nodes just remained walkable, no matter what I did. I don’t know why, I probably made some stupid mistake. However, this was the point where I had to stop, because I got… let’s say annoyed. Okay, let’s not say annoyed, let’s say “ready to punch a baby seal”. But it wasn’t in vain, because in theory I have a very elegant solution, one I really like. Once this “make area not walkable” thing starts working. Which it won’t for now, because I’m moving on. Not sure what I’ll work on today, but pathfinding won’t be it, that much I know.
I’ll start a little later than usual today, because I have to go to the grocery store first. I’m super hungry for some reason, it’s almost as if I haven’t eaten anything yesterday.
See you guys tomorrow!
