0 votes

I am having issues coming up with an id system that can work with negative positions in a TileMap, so something like (-1, -1).

This is how it looks like right now and I'm wondering what my options are.

Generally, how would you make AStar work with negative values? I'm hitting a wall since p_id in AStar only accepts values >= 0.

func calculate_point_index(point):
  return point.x + map_size.x * point.y
in Engine by (15 points)
edited by

1 Answer

+1 vote
Best answer


You have to calculate an offset of the map and subtract it from point coordinates, i.e. if your script extends TileMap, you may use get_used_rect():

# get map limits
onready var map_limits = get_used_rect()

# calculate cell index
func calculate_point_index(point):
    # subtract offset from position
    point -= map_limits.position
    return point.y * map_limits.size.x + point.x
by (56 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.