When I first got pathfinding to work, like you saw in the prototype and had made somemore work on it, I though well now there can't be much more work, but there were and is still much more work, cause I underestimated how hard pathfinding is!
The performance issue
Pathfinding is very cpu needing, becuase of that you need to write your algorith, very good. There can't be anywere it will take too much time on something or else it will lag and it will lag more the more you get into the game!
That was something i found out, when I tried my pathfinding more. It lagged, so I had to fix it, because if it could lag, with a little testlevel as that, then it was going to be a nightmare, when we started making real levels.
Performance is hard! |
Fixing it
So what did I do to fix this performance issue I had?
Simple, google is your friend. I began to search on the internet to find out how others have done and I found something, that was genius! So I started making my pathfinding much better performancevise and it worked! Now it is much much faster and works much better!
![]() |
Google is wonderful! |
Where did I fuck up?
So what was it that had been taking so much performance?
Well it was two things, the first is finding out if a node that is about to get added, is in open or closed list. The error I made was going through both open and closed list everytime I needed to get that info and it was called way too many times, so that it made our game lag.
The secound error was my collision detection, I again had stored the infomation in a list and it took too long time to go through it, everytime I needed to know if a node was on a unwalkable or walkable place.
Well sometimes you fuck up! |
So how did i fix it?
I used the same solution for both problems. Instead of using an list to both, I used a twodimensional array of bools. To find if the node has been in the open or closed list, I checked with coordinates x and z, that I just entered into the twodimensional array. The same goes for collision detection I run through all the coordinates multiplied by 10, because a array can't have comma numbers. So I just sent the position and entered x and z into my collision array and it very quick returns an answer!
So your done now RIGHT?
Unfortunalty no, there is still much to do. Since pathfinding is one of the core mechanics, it has to work like a charm. And there is also detecting other moving object with the pathfinding, while having good performance. So there is a lot of work in pathfinding left, but i have also gotten a long way!
![]() |
Still a lot to do |
Any problems or questions, just send me a mail at headlesshoboentertainment@gmail.com
Ingen kommentarer:
Send en kommentar