d

_create_astar_points() in Godot 4

dev_zombie

Im trying to get this to work within Godot 4.
Im having issues with the _create_astar_points() func around comparing the position of the start/goal points with the cell positions.

I have tried a few varitions but i cant seem to get it to work

func _create_astar_points() -> void:
    # Sets cells ID by iteration order
    var cell_id := 0
    for cell in walkable_cells:
        _astar.add_point(cell_id, cell)

        # Store the start and goal point IDs
        if Vector2i(cell) == local_to_map(to_local(start_point)):
            _start_id = cell_id
        if Vector2i(cell) == local_to_map(to_local(goal_point)):
            _goal_id = cell_id

        cell_id += 1

this is the error i get


if i print the results of local_to_map(to_local(start_point)) and local_to_map(to_local(goal_point)) they reutrn (0, 0). No matter what I try it always seems to be like this

Any ideas how to make this work?


  • Nathan Lovato replied

    Could you please upload your Godot project as a ZIP to a platform like Google Drive or an equivalent, and share the link here? I'll open it in Godot and try to figure out the issue. I need to dive into the project and possibly use the debugger to help you here.

  • d
    dev_zombie replied

    Sure project is here on onedrive  https://1drv.ms/u/s!AnMJ1QjhiULirWdEIzlEgFkkByK4?e=pu7LdR

    Thank you in advance.

  • Nathan Lovato replied

    Here you go! The answer in video. In short, your AStarGrid node was missing a TileSet resource. In this 4mn video I go over how I figured it out briefly, and use the debugger to verify that the code is now working as intended:

    https://vimeo.com/872180403/c51a1e642d?share=copy

    I hope this helps!

    2 loves
  • d
    dev_zombie replied

    Yes this worked amazing thank you so much.
    Your video really helped me to understand some parts I didnt understand with the tilemap too so big thank you on that too.