Game Development Community

Is this possible in script

by Steve D · in Technical Issues · 05/11/2008 (8:55 pm) · 2 replies

I'm working on a turn based combat game, only 1 bot moves at 1 time, bot combatants will number anywhere from 10ish to probably 30ish. My biggest hurdles are working out the movement during fighting. If I don't have some kind of grid that all the bots adhere too there would be a few problems - some bots all colliding with each other if they are directly attacking a bot in common and obviously moving around bots in the way.

I tried an A* system in c++ code with nodes but the problem is the number of nodes - for a minimum size battlefield, spacing each node 1.5 world units apart - I have roughly 1100 nodes for a battlefield. Not only does this slow down the editor considerably but even a few of these grids adds thousands of units to the game and really increases the load time. One solution I thought of is creating the grid on the fly but the problem is it needs, or at least on my laptop which is pretty new, about 3 seconds to calculate all the path data which locks up the game.

So would it be reasonably possible to create an A* system in script without nodes, just using a huge array to hold over a thousand coordinates? This way when the player moves a bot from point A to B, point A and B will actually be the closest grid coordinates matching where the mouse clicked. This would also allow for a bot to have eight grid coordinate spots around him which can be marked as occupied or open so bots can't bunch up on one side if they are attacking the same person.

Is there a better way of doing this? I can't see getting around needing a grid, kind of like a checker board, so each bot can occupy a single coordinate and mark that coordinate as occupied. But the problem is when you have to loop through over a thousand coordinates let's say a dozen times that could mean a second or two of freezing while the engine calculates it.

I realize this might be a broad question and the answer might be "anything is possible in torque" but I was just trying to brainstorm and see if anyone could give me any better ideas on how to approach this or is a grid system the only real way to go with this?

#1
05/12/2008 (12:29 pm)
I'm sure you can make an A* function in C++ without the nodes having to be part of the editor. Besides, writing code like that in script is actually slower than finding a way to do it in C++. May I suggest instead of using nodes with paths from each node to another, have "squares" of terrain. It's very efficient an if you can right an algorithm to check whether or not each square is unwalkable on grid load, than you don't even need it to be in the editor. If you wanna be really complicated with it you could even write it to match a terrain square, and do checks/variables based off of that. For a better explanation of this, see Ramen Sama's blog on the topic Here.
#2
05/12/2008 (12:49 pm)
Try the Flexible A* Pathfinding System. Right now, I have over 100,000 nodes (Only took about 10 seconds to place!), and after the initial save, the loading time is less than one millisecond (yes, I've timed it). Also, unless you've got a really complex level, like a maze, than the pathfinding time is increadably fast, and it has a system where you just enter the (x,y,z) of where you want to go, and the bot will travel to the closest node!

You would have to make some adjustments in order to do the 'occupied/unoccupied' system, but you could just do a collision or stuck callback, and make a new path from there.