0 votes

TL;DR: how should a group of units should go from a tile to another while :
1)being spread out on the destination tile
2)Being blocked by forest borders on tiles (impassable)

I'm doing a virtual version of a board game with troops moving from hex to hex, multiple together. I don't know how I could manage so they are always spread out on a tile they move to. I already have the map in a tilemap:

^^Started from the hexagonal tiles demo^^

also, the troops shall not go through forest borders (to or from) unless when controlling a special tile with 2.
As of now, since you can't have a script on a tile, I started a script on the tilemap with the passable borders var passableCase=[ [false,true,true,false,true,false], [true,true,true,true,true,true], [true,false,true,false,true,false], [false,true,false,false,false,false], [false,true,false,true,false,false], #Tile5 [false,true,true,false,true,false], [false,true,true,false,true,false], [true,true,true,true,true,true], [false,true,true,false,true,false], [false,true,false,true,false,false], #Tile10 [false,true,false,false,false,false], [false,true,true,false,true,true], [true,false,true,false,true,false], [true,true,true,true,true,true], [true,false,true,false,true,false], #Tile15 ]
As can be seen, not that good...

Hope I'm not too hard to understand; haven't done as much godot programming as I would like.

in Engine by (49 points)
edited by

1 Answer

0 votes

I may not understand what you want to do but I'll try...

To work with tiles (since could be complicated to use areas) you can use the tile ID, make a dictionary with characteristics for each ID.
You can get the cell ID from the TileMap.world_to_map position.

Now if what you want is to do is related to pathfinding, could be a lot more complicated (not for Godot but for the design itself), the class AStar could help there working on a parallel grid for the logic.

by (7,922 points)

I just tested using Tilemap.world_to_map and it's exactly what I need(just had to add my offset since they are hexes):
onready var sprite = get_node("../sprite") onready var tile= world_to_map(sprite.get_pos()+Vector2(384,335))
Big thanks to you :D

Also your suggestion really helped figuring out my first point of spreading form the center with only getting the destination hex position with (for example moving up-right)
for i in movingWarriors: movingWarrior.get(i).set_pos(Tileset.get_cell(tile.x+2,tile.y).get_pos()+Vector2(i,i))

Now, since I can't give scripts for my tiles, is my way the best way to store the "walls" on each sides of the tiles?

Maybe you can use binary numbers to get all the combinations in a more simple way than true-false (which is almost the same).

Instead of [false,true,false,true,false,false] you can say 010100 or just 20.
With bitwise operations you can identify the open sides.

I don't know if there is a more visual way to organize that.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.