I’m thinking about doing a turned based action game, a bit like the battles in Heroes of might and magic. But probably sci-fi.
I think I can pull of a decent pathfinding script that will suit my needs, if I can get help on this one:
Is there any smart way of finding out if there is something at a certain spot or not?
I thought about rayCasting from above and see if I hit anything but the ground, but is there a better way? Objects can be big and have odd shapes so just comparing their positions won’t do.
Okey, well something like this:
I will not have a visible grid, I just want to be able to tell if a unit can reach a certain square in their turn, so if you hover your mouse over a square it will either turn red (if you can’t reach it) or green and highlight the path (if you can reach it).
My plan was to:
check if the goal is within the maximum walking distance with no obstacle
collect all obstacles
find the path.
I’m stuck at number two, I have an idea how I will solve 3 (I’ve been reading and collecting posted blend files)
Thanks for the advice, but for things like terrain or such, when the object is bigger than a tile how would I go about that? (a river or a big rock or wall) I could manually type all the impassable tile for every map but I hoped to write a script that could find that out at start-up.
I would gladly take a look at your script.
And now I will be going on a short trip, this thread might be revived at Wednesday or Thursday.
start is a list: [x,y]
goal is a list: [x,y]
passable_tiles is a two dimensional list that represents the grid, 1 is passable, 0 is impassable: [ [1,1,1,1], [ 1,1,1,1], [1,1,1,1], [1,1,1,1] ] is a 4 by 4 grid, all passable. You can get a single tile with:
passable = passable_tiles[x][y]
if passable == 1: ect
Thats pretty much it, the init script puts the pathfinding module on GameLogic, creates the passable_tiles list and shows the mouse. The update script finds a path when the lmb is pressed and draws it on the grid.
The pathfinding script is pretty nooby (as it was my second attempt at pathfinding), but I guess its allright. It does not take into account a cost system (deters the path from going over a tile), but you don’t have to worry about that I guess.