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
asked Nov 29, 2018 in Engine by laedo (15 points)
edited Nov 30, 2018 by laedo

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
answered Nov 29, 2018 by leonidboykov (56 points)
selected Nov 29, 2018 by laedo
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.