
A procedural hex-grid island builder in Unreal Engine. Perlin noise determines land vs water tile placement; offset rows give the classic flat-top hex layout. Players use an RTS camera to navigate, place tiles, and watch their island grow in real time.
x * HexWidth + (y%2 * HexWidth/2) and y * HexHeight * 0.75, derived analytically from 2 grid axes with no pre-baked data.WaterThreshold — above → land tile, below → water tile.Every tile position is derived analytically from its grid coords. Perlin noise at the same XY determines biome. No pre-baked maps.
void AHexGridIslandBuilder::GenerateIsland()
{
for (int32 y = 0; y < GridHeight; ++y)
for (int32 x = 0; x < GridWidth; ++x)
{
FVector HexLoc = GetHexLocation(x, y);
const float NoiseVal = PerlinNoise->GetNoise2D(x * NoiseScale, y * NoiseScale);
// Above threshold → land, below → water
UClass* TileClass = (NoiseVal > WaterThreshold) ? LandTile : WaterTile;
SpawnTile(HexLoc, TileClass);
}
}
FVector AHexGridIslandBuilder::GetHexLocation(int32 x, int32 y)
{
// Flat-top hex layout: odd rows offset by half hex-width
const float XOff = (y % 2 == 0) ? 0.f : HexWidth * 0.5f;
return FVector(x * HexWidth + XOff,
y * HexHeight * 0.75f,
0.f);
}
void AHexGridIslandBuilder::SpawnTile(FVector Location, UClass* TileClass)
{
FActorSpawnParameters Params;
Params.SpawnCollisionHandlingOverride =
ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
GetWorld()->SpawnActor<AActor>(TileClass, Location, FRotator::ZeroRotator, Params);
}