how can i detect cell tile around my player ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By potatobanana

hi, want i want to do it, i want to detect all tile around me, and then i can change how much i can detect, for exmple 2 tile around me.

how can i detect cell tile around my player?
for example, that red box is my player
i want to detect all 2 tile around me, how should i do it?

:bust_in_silhouette: Reply From: Inces

This is a code to detect every tile in 8 directions in range of X tiles from TILE :

func getneighbours(TILE,X) :
      var surroundingtiles = []
      for a in range(-X,X):
             for b in range(-X,X):
                    var currenttile = Vector2(a,b)
                    if not surroundingtiles.has(currenttile) and not currenttile = TILE  :
                          surroundingtiles.append(currenttile)
      return surroundingtiles
     

I made it on the go, it might have some inaccuracy :wink: