Showing posts with label Path Finding. Show all posts
Showing posts with label Path Finding. Show all posts

Monday, August 14, 2017

Update 46: OpenTile

Two years can really fly by. Growing families, big work projects, small home projects, and as many distractions as you can throw at a sticky wall, here I am. I haven't been doing nothing, I just haven't been writing about it. I'm trying to change the not writing about things problem today.

One of those mini projects I've been working on is very relevant for this project. About a year and a half ago, I started a GitHub project I've called OpenTile. OpenTile is an opensource solution to create the building blocks and data structures for a tile based game. There is no UI, apart from the ASCII files, but it's being built in C#, with a branch for Unity3d. There is currently functionality for basic path finding, possible available tiles (for movement), cover, as well as a number of utility functions. 

I've found this framework really helpful for building a game. I'm able to focus on fundamental functionality such as path finding or cover in a simple ASCII UI, and then it's much easier to integrate the changes into a full 3d engine - with the confidence that it works.

In the screenshots below you can see two simple examples that show the output of path finding on a large map with varied obstacles.





In Unity3D, this is what the result looks like on a small test map:





Sunday, January 26, 2014

Update 28: Random Levels - Part 2

Happy with my new random levels, I quickly discovered that some of my map combinations didn't make much sense, especially when rivers or roads were involved. In the sample below, you can see two river tiles are connected with a tile with no river - it just doesn't look right.



To make better maps, I needed to a river/road to start on one edge and finish on the opposite edge. I started a prototype to solve the problem, migrating over a few level data structures from my game - fortunately my design and structures were generic enough to allow this. My initial plan was to take my level area, draw a continuous river/road across the level, and then fill in the blank tiles with random tiles. To work through this, I created a simple console application to output ASCII, using these tiles as samples:

╔0══╗╔1|═╗╔2══╗╔3|═╗╔4|═╗╔5══╗╔6══╗
║   ║║ | ║─────║ └────┘ ║──┐ ║║ ┌──
╚═══╝╚═|═╝╚═══╝╚═══╝╚═══╝╚═|═╝╚═|═╝

With the templates in place, I started work on the tiles. The first level, running my current level creation algorithm, looked like this, again highlighting how ridiculous this all looks:



Next, I went to work drawing the river first, and then filling in the remaining tiles. This wasn't too difficult, starting with a simple (3x3 level): 



...and scaled nicely, getting more complex quickly (8x8 level):



Finally, I adjusted the path-finding of the river, so that it wouldn't drop back on itself. Essentially, if I start from the left, let my river go up, down and right, but never backwards (left). The output looks like this:



This is exactly the result I was looking for. Additionally, it scales up easily, I ran some 100x100 samples in less than a second.  The next phase is to recreate these tiles in my game, the next post will be about this process. If you'd like to play with the prototype, I've posted the level creation tool online here.

Friday, February 15, 2013

Update 7: Pathfinding

I need to be able make my players move from point A to point B, avoiding any objects on the way. This is basic pathfinding. Pathfinding is one of those simple features that seems to be difficult to do properly. There are plenty of games that just don't quite get it right. Taking this into account, I knew I wouldn't be writing mine from scratch.

I analyzed a number of different tools, before selecting the A* Pathfinding Project. I found this project both really simple to use... and difficult to use. The primary problem I was having was that my character was stopping half way towards his destination. The sample wasn't quite right and I pulled my hair out for a few days, still unable to get it to work. 

I added in some basic movement, but my player kept hitting walls and falling over (shown below). While hilarious, it wasn't the result I was looking for. It turned out to be a physics problem. While my pathfinding is not complete, I was a good introduction and I did have some positive results (not shown below).