Hello,
I am creating a world map with hexagons, generated at runtime. I need to generate the PointGraph at runtime as well, establishing the node positions and connections manually.
I have read the documentation, and successfully created the grid - with an issue.
The WorldMap I have is very large (1000 x 1000 units). Yet the PointGraph created is really small (like 1x1x1 units).
It has the perfect shape of the landmass, but of course, for some reason it’s created really small instead of covering the actual landmass size.
Any ideas why this could be happening? and how to fix it?
Here’s a pic of what I mean. Notice the size of the map, and behind it the size of just one tile of the map. The PointGraph should be huge as well.
And my generation code here (sorry if it comes out as a mess):
/*
AstarPath.active.AddWorkItem(new AstarWorkItem(ctx => {
for (int continent = 0; continent < WorldMap.continentTerritories.Count; continent++)
{
continentTerritory = WorldMap.continentWorldMapPathfind[continent];
//Debug.Log("Continent " + continent + " territory: " + continentTerritory.Count);
// Create Point Nodes
for (int worldMapTile = 0; worldMapTile < continentTerritory.Count; worldMapTile++)
{
currentPointPos = GetGlobalTilePosition(continentTerritory[worldMapTile], WorldMap.worldX, WorldMap.worldY, WorldMap.worldMapLevels, WorldMap.overworldLevels);
currentPointPosInt = new Int3((int)currentPointPos.x, (int)currentPointPos.y, (int)currentPointPos.z);
Debug.Log("Creating point nodes for worldMapTile: " + continentTerritory[worldMapTile] + " / currentPointPos: " + currentPointPos + " / currentPointPosInt: " + currentPointPosInt);
continentNodes[continent].Add(continentGraphs[continent].AddNode(currentPointPosInt));
//Debug.DrawRay(currentPointPos, Vector3.up * 50f, Color.blue, 10f);
}
// Connect Point Nodes
for (int worldMapTile = 0; worldMapTile < continentTerritory.Count; worldMapTile++)
{
worldTileData = WorldMap.worldMapTiles[GetGlobalTileLevelIndex(continentTerritory[worldMapTile], WorldMap.worldX, WorldMap.worldY, WorldMap.worldMapLevels, WorldMap.overworldLevels)];
//Debug.Log("Connecting node " + worldMapTile + " / continentTerritory: " + continentTerritory[worldMapTile] + " / tileData index: " + worldTileData.index);
for (int neighbor = 0; neighbor < HexaNeighbors/2; neighbor++)
{
if (neighbor == HexaNeighborBotLeft && worldTileData.neighborBotLeft >= 0)
{
currentNeighbor = GetGlobalTileLevelIndex(worldTileData.neighborBotLeft, WorldMap.worldX, WorldMap.worldY, WorldMap.worldMapLevels, WorldMap.overworldLevels);
if (WorldMap.worldMapTiles[currentNeighbor].continent == continent)
{
for (int checkingTerritory = 0; checkingTerritory < continentTerritory.Count; checkingTerritory ++)
{
if (continentTerritory[checkingTerritory] == worldTileData.neighborBotLeft)
{
GraphNode.Connect(continentNodes[continent][worldMapTile], continentNodes[continent][checkingTerritory], movementCost);
//debugPos1 = new Vector3(worldTileData.tilePosition.x, 10, worldTileData.tilePosition.z);
//debugPos2 = new Vector3(WorldMap.worldMapTiles[currentNeighbor].tilePosition.x, 10, WorldMap.worldMapTiles[currentNeighbor].tilePosition.z);
//Debug.DrawRay(debugPos1, debugPos2 - debugPos1,Color.cyan,10f);
break;
}
}
}
}
if (neighbor == HexaNeighborBot && worldTileData.neighborBot >= 0)
{
currentNeighbor = GetGlobalTileLevelIndex(worldTileData.neighborBot, WorldMap.worldX, WorldMap.worldY, WorldMap.worldMapLevels, WorldMap.overworldLevels);
if (WorldMap.worldMapTiles[currentNeighbor].continent == continent)
{
for (int checkingTerritory = 0; checkingTerritory < continentTerritory.Count; checkingTerritory++)
{
if (continentTerritory[checkingTerritory] == worldTileData.neighborBot)
{
GraphNode.Connect(continentNodes[continent][worldMapTile], continentNodes[continent][checkingTerritory], movementCost);
//debugPos1 = new Vector3(worldTileData.tilePosition.x, 10, worldTileData.tilePosition.z);
//debugPos2 = new Vector3(WorldMap.worldMapTiles[currentNeighbor].tilePosition.x, 10, WorldMap.worldMapTiles[currentNeighbor].tilePosition.z);
//Debug.DrawRay(debugPos1, debugPos2 - debugPos1, Color.magenta, 10f);
break;
}
}
}
}
if (neighbor == HexaNeighborBotRight && worldTileData.neighborBotRight >= 0)
{
currentNeighbor = GetGlobalTileLevelIndex(worldTileData.neighborBotRight, WorldMap.worldX, WorldMap.worldY, WorldMap.worldMapLevels, WorldMap.overworldLevels);
if (WorldMap.worldMapTiles[currentNeighbor].continent == continent)
{
for (int checkingTerritory = 0; checkingTerritory < continentTerritory.Count; checkingTerritory++)
{
if (continentTerritory[checkingTerritory] == worldTileData.neighborBotRight)
{
GraphNode.Connect(continentNodes[continent][worldMapTile], continentNodes[continent][checkingTerritory], movementCost);
//debugPos1 = new Vector3(worldTileData.tilePosition.x, 10, worldTileData.tilePosition.z);
//debugPos2 = new Vector3(WorldMap.worldMapTiles[currentNeighbor].tilePosition.x, 10, WorldMap.worldMapTiles[currentNeighbor].tilePosition.z);
//Debug.DrawRay(debugPos1, debugPos2 - debugPos1, Color.green, 10f);
break;
}
}
}
}
}
}
}
}));