Skip to main content

Posts

Showing posts with the label a star

The basics of A Star Pathfinding

Someone wanted to know how the code works for basic A* path-finding. Rather than reply in Facebook, I've made a quick post for it here. 1. create an array of nodes to represent your level.  It can be nodes with connections, or it can be a list of co-ordinates where connections are assumed to be NESW where a node exists.   Example 1:   level = {"001":[["002", 5.0], ["003", 5.0]], "002":[["001", 5.0], ["003", 5.0]], "003":[["002", 5.0], ["001", 5.0]]}    This is a dictionary based "mesh" type array, for easy reading. You can see it has 3 nodes arranged in a triangle. Each node is connected to two others, and in this case, the distance between each is 5.0 units.    It's easy to see how this mesh could be expanded. You just need more points. Each point must include its two neighbors and the distance between them.   Example 2:   level = [[0,1,1,0], [0,0,1,1], [1,1,1,0], [1,0,0,0...

RTS pathfinding

I spent some time today looking at the possibility of adding A* path-finding to my game. I've used it in the past and I actually got it running pretty fast, even though it's written in python. So I was optimistic about replacing my less than stellar dumb path-finding with A*. However I ran in to some problems. First is the fact that I'm working with quite a fine graph, each infantry man takes up one tile, and tanks and the like take up several (a big tank takes up something like a 12x12 chunk of tiles. When you're working with a graph which might be several hundred tiles square, you get slow performance. When I've used it before I worked with either a pretty course grid, or with navigation nodes. [a* with grid] [a* with nodes] Both these situations give you quite a limited grid and so, good performance. Working outdoors with such a fine and almost unlimited grid makes the algorithm work too hard, especially when you have a lot of agents. Looks...

General Principles for Reducing Logic Overhead.

Today I was reading Blender Artist's Game Engine Forum when I came across a post about very high logic overheads. Of course slow game performance is a real problem with a lot of indie games, and low frame rate can easily be enough to turn someone off your game before they even really get started. It's an important issue for indie game-devs and hobbyists alike. [LAG=game over] So I decided to write a blog post about it. First of all I should point out there are lots of areas of overhead in a game. One area that often causes lag is graphics, a game engine like Blender is still using quite old methods of rendering and lighting so you can't expect too much from it. There are easy ways to reduce rasterizer overhead which I think I've talked about before many times over at Blender Artists. The problem the BA poster was having though was specifically with Logic, i.e python scripting and the Game engine logic bricks. With games developed by hobbyists it's comm...

Coding general AI.

As promised I've spent most of my time this week on coding basic gameplay. [text above each agent displays debug info] I started out having separate state machines for AI decision making and actions/animation. Sometimes AI control calls for very rapid switches of states which would also disrupt the animations. Causing them to stutter or jump. But by setting up Animations to only switch after a short delay I eliminated the problem you get with having AI and actions in the same state. If a call to switch animation occurs, but rapidly switches back (like stopping for an instant when walking) the switch is ignored. So I refactored them in to a single finite state system with inheritance helping to structure things like animation and path finding. [Blocked in!] AI is pretty basic. They just try to get towards you avoiding squares they've already visited. But it works surprisingly well. It's easy to get blocked in by the enemy, but you can use the nature...

Speed Improvements Again.

I've already gained some speed improvements from how I'm handling dynamic blocking objects, but I wanted to revisit some of my older code and see if I could clean it up a bit. One of the things I was doing before to make faster calculations was to strip the A star graph down to a bounding box around the start and end + a small border. Actually this turned out to be slowing the code down once I reorganized things. The only time this would speed things up is if the map were really huge, the start and end locations were really far apart and every room on the map was open... So this got dropped for now. I was doing some esoteric things with getting the nearest node in the graph for a start and end point, which was almost taking longer than the A star search (on short routes)! So that got cleaned up. The route smoothing pass cleans that up anyway. Here's the end results for comparison: Almost a 50% reduction in some cases. It may not seem important but once there are ...

Side Projects V2.0

I've been working on a number of side projects recently, so no actual work on Treasures of the Deep Dwellers. However all but one of those side projects have been aimed at testing some ideas with a view to restructuring the project or developing key components which were missing. When I finished working on the most recent version, it felt like I was nearly ready to put out a demo... but after trying it out for a while I wasn't satisfied. Movement calculation was too slow, the characters and AI were too complicated and not well designed. Adding to them was becoming too much of a chore. And there was something wrong with the pathfinding... I took part in a game jam and had the opportunity to work on an FSM ( Finite State Machine ) for character management. The version I designed for the competition was a little limited because I didn't use classes , I had to define all properties for all states at initialization of the game. The result was pretty messy, but it worked m...

Speed improvements.

Yesterday was headache day, so no development. Today was coding day. Found a big BUG! I've been using a dictionary to contain my navigation data, that's to remove the need to recalculate the graph after every run of A*. I just made a deep copy of the original dictionary. I was deep copying the dictionary, then cropping the new dictionary to a bounding box around the start and finish points, by reducing the size of the graph it makes A* run faster. Unfortunately deep copy, or even dict.copy() are very slow operations. So while a long distance calculation of A* was taking 0.012 seconds, the deep copy operation was taking 0.12 seconds! 10 times slower than the A* function. A big drain on resources indeed. (nearly half a second for just six enemies!) So I started by rewriting the cropping function. Now it crops data out of the original dictionary, copying entries and appending them to a new dictionary. Because it only copies entries inside the bounding area this...

Navigation Redux and first steps of AI

Click the image for a video of current navigation and AI progress.

Reboot.

I took some time away from the project for the last few months. I've been investigating some different things that I wanted to get in to the game, but they needed a lot of experimentation to find the best configuration. I also toyed with the idea of spinning off a new, less complex project but didn't quite go through with it. I've got a couple of things which are ready for further development if I ever decide to focus on them though. The first thing I did was to investigate non grid based movement. I know it's a step away from hard core roguelikes, but as well as being faster than grid based movement, it's easier to manage. The experiment was for a RTS game, but most of what I made can easily be reused in the RPG.  I also spent some time working on particle effects and time control. I briefly entertained the idea of making the game a real time RPG with the ability to slow down time or stop it altogether to aid with strategy. In the end I'll only b...

Large Monsters in game.

After spending a lot of time going through the code and adding in some special conditions I now have large monsters working pretty much as I want them. Well, as far as movement is concerned anyhow. When it comes to combat there really shouldn't be any trouble, it'll just be a case of checking which characters are next to the occupied squares for the intention of performing an attack. One of the big monsters in game. The green circle represents the "home" square from which movement. I've prepared a video which shows how the routes are calculated and how it looks in game. You can see it below: Working on this has thrown up a whole host of issues with the code so far. There'll be a lot of polishing going on over the next few days. One problem is that at times the game was calculating things based on a static floor height of z=0.1 rather than a dynamic z=walkmesh_data height. That will have to be corrected if my later experiments with variable heig...

Large Monster Implementation.

One thing which has been a cornerstone of my development framework so far has been Large Monster Implementation (from this point referred to as LMI). It's something that I've said I wouldn't give up on. So as it became increasingly likely that LMI wasn't going to work, or was going to have to require two completely different movement and combat systems working in tandem I became a little downhearted. A giant spider, and look, it really is GIANT! I had built my level prefabs to include a two square wide door, specifically to allow plus size monsters. Many of the monsters I had already designed had small and large variants. It was a real downer. Anyway, my original plan was to have two sets of tile data, one for small tiles and one for large. I would keep track of movement in both, and then share data between them. it was horrible complex to try and code, and I just gave up, just trying to work around the issue on other things that I could actually do. Today ...