I've done a little work with tilemaps and need help with finding if a 5x5 grid is within certain conditions.
Checks i need to do are:
1. Find a grid that has a tile with a block in it.
2. Check the surrounding blocks along X -2 and +2 if they are blocks.
3. Then check along the y axis if all blocks are empty.
4. Save the world position of the starting block.
So far i have steps 1 and 2 done but am unsure how i can do the y axis check.
I started doing the y check and realised i'm not 100% sure how to get it to scan the entire grid.
I'm also pretty new to vector2 arrays so don't believe i've correctly set the append.
After Thoughts
Ideally i would like this be able to check left and right floors as well as ceilings and floors for available 5x5 grids but understand mabye i should get the floor checking done first.
Would it be possible to record the info into a Vector3 array? i.e Vector3 (X,Y,Direction)
export var width = 500
export var height = 500
var Placementneighbour_dirX = [Vector2(-2,0),Vector2(-1,0),Vector2(1,0),Vector2(-2,0)]
var Placementneighbour_dirY = [Vector2(0,-1),Vector2(0,-2),Vector2(0,-3),Vector2(0,-4)]
PlacementArray = PoolVector2Array ( )
onready var tilemap2 = get_node("TileMap2")
func FindPlacementPoints():
for x in width: #Loop through map width
for y in height: #Loop through map height
if tilemap2.get_cell(x, y) != tilemap2.INVALID_CELL: #Is cell Valid Block
var number_of_neighbour_walls = 0 #Create Counter at 0
for directionX in Placementneighbour_dirX: #StartLoop through Array
var current_tileX = Vector2(x + directionX,y) #Add array X to current tile
var current_tileY = Vector2(x,y + directionY) #Add array Y to current tile
if tilemap2.get_cell(current_tileX.x, current_tileX.y) != tilemap2.INVALID_CELL: #Check X line is Valid Block
if tilemap2.get_cell(current_tileY.x, current_tileY.y) == tilemap2.INVALID_CELL: #Check Y line is Empty
number_of_neighbour_walls += 1 #+1 to Counter
if number_of_neighbour_walls > 5 : #If X line == 5 blocks
PlacementArray append ( Vector2 (current_tileX )) #Save position to array
Any and all help appreciated even if you can send links to usefull resources.