0 votes

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?

enter image description here

in Engine by (394 points)

1 Answer

0 votes
Best answer

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  :
      return surroundingtiles

I made it on the go, it might have some inaccuracy ;)

by (5,607 points)
selected by
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 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 webmaster@godotengine.org with your username.