Jumat, 16 November 2012

AI pathfinding nodes


I started writing an A* pathfinding system with branching nodes, each node is linked to it's closest eight nodes for more efficient path plotting. I wrote a script that would cycle through them and link them to their eight closest nodes who's paths don't intersect walls or obstacles. Above is the turn out when I got it right, below is the result when I accidentally required rather than disallowed raycasts intersect with walls and obstacles.



Two more examples, above just two links each, below is four which is probably the one I'll stick with for speed.



templates-office.com Pathfinding, Stealth

Light level


Light level is the first thing I've completed, the concept for measuring light seemed simple but it was so essential to the gameplay I decided to do it first to make sure it could be done efficiently and accurately.

The method is quite simple, since we're already using light objects in unity to create light we can add extra code to each of them to check how much they're lighting up the player. All the check does is raycast the distance from the light to the player to check for walls in the way, then if it finds the path clear it measures the distance to the player and assigns a percentage based on the distance. Unity handled all of this very well and the code ran smoothly with no difference in frame rate.

Past this there are still a lot of improvements to be made to this system, things like ambient light, how close the player is to walls and special areas like outside or rooms with windows. Also the checks run to the centre of the player so sides of the player poking out doorways won't register as putting the player in light and if it's dark in the middle of a room the player can walk through undetected even though logically the character would make a silhouette on the wall behind him if it was lit well enough. That said there's always room for improvement but as long as the basic system works I can go ahead with the project.
templates-office.com Stealth