+1 vote

Hello every one. I'm trying to make a puzzle game, but im running into some problems.

In my game only the pieces on the red line should be deleted but it deletes other pieces too, what is the best way to do somthing like this?

Path and pieces that should delete

The green lines (image 2) are the deleted pieces that shouldn't be deleted.

after deleting pieces

Godot version 3.2.1
in Engine by (18 points)

Thank you very much for the HUGE help. I'm not sure what to do with the getpath() func in line 13.

var path_to_end = _get_path(point, known_path.back())

Ohhh yeah they have their paths as member variables (declared in the class outside of a function so any function can access it). I refactored my code to not use member variables.

Here's my implementation of _get_path():

func _get_path(map_start, map_end):
    var start_point_index = _calculate_point_index(map_start)
    var end_point_index = _calculate_point_index(map_end)

    var point_path = aStarNode.get_point_path(start_point_index, end_point_index)

    if point_path.empty():
        printt("unreachable", map_start, map_end)

    return point_path

Really it should probably be called get_map_path() but my naming skills are great. :P

I was able to get it working! Thanks alot for the help.

Multi path

I also found out, that, if there is a loop, it won't mark it as part of the path, wich sense.
I tried to add code to the checkforpath(), but I got an overflow error.

enter image description here

Nice! So the reason the loop doesn't register is because the initial connection is disabled before finding the path to the end. So it starts at the point right below it and doesn't find a path to the end so it's not added.

I would have to think more about how to solve that. The work would be done in the check_for_path() function. If there is a loop, the path length would have to be size 4 or larger.

I made a function that somewhat works, but it also adds unwated connections. And its a BIG mess.

func check_for_loops(point, known_path, potential_paths, initial_loop):
var connections = get_connected_positions(point)
for i in connections:
    if i in known_path:
    if i in potential_paths:
    printt("get_connected_positions: ",i)

if potential_paths.size() > 3:
    for i in get_connected_positions(potential_paths.front()):
        if i == initial_loop:
            print("loop_completed: ", potential_paths)
            return potential_paths

if !potential_paths.empty():
    check_for_loops(potential_paths.front(), known_path, potential_paths, initial_loop)
return potential_paths

The function is called from check_for_path(), I added an else after if not path_to_end.empty():

loop test

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.
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.