Hello
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.
Anyway:
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.
So your trying to find if something is blocking your path?
Maybe everytime the player reaches a new node it casts a ray to the next one to see if its clear.
I’m not so sure what you’re asking, but I think rays are what you need to do unless its tile based.
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.
Here is the pathfinding script with a demo. Its based on the pseudo code from:
To run it save it somewhere, open it up, open the pathfinding.py text file and then save it as pathfinding.py in the same directory as the .blend. Re open the .blend and play it.
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.