0 votes

Hi all, if I add to my 'obstacles' array like so:

obstacles = []
obstacles = get_used_cells_by_id(13)

then the astar implementation I'm studying works.

However, if I add like the following:

obstacles = []

then the astar doesn't walk around those obstacles.

This is the astar fuction:

func astar_add_walkable_cells(obstacles = []):
    print("obstacles - ", obstacles)
    var points_array = []
    for y in range(map_size.y):
        for x in range(map_size.x):
            var point = Vector2(x, y)
            if point in obstacles:

            # The AStar class references points with indices
            # Using a function to calculate the index from a point's coordinates
            # ensures we always get the same index with the same input point
            var point_index = calculate_point_index(point)
            # AStar works for both 2d and 3d, so we have to convert the point
            # coordinates from and to Vector3s
            astar_node.add_point(point_index, Vector3(point.x, point.y, 0.0))
    return points_array

What would make the astar not use my obstacle when added via a push_back VS a singular assignment?

Thanks so much...

UPDATE The following code works. But why? Surely a push_back would work?

obstacles = obstacles + get_used_cells_by_id(10)
obstacles = obstacles + get_used_cells_by_id(11)
obstacles = obstacles + get_used_cells_by_id(12)
obstacles = obstacles + get_used_cells_by_id(13)
obstacles = obstacles + get_used_cells_by_id(14)
asked Jan 6 in Engine by Robster (808 points)
edited Jan 6 by Robster

Please log in or register to answer this question.

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.