2D - Detecting nearest and multiple entity in a path2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tomandrieu

Hello,

I’m trying to create a level selector scene where level are represent by buttons, a path2D and a clic on a button allows the player to navigate on the map.
But i want to make a lock/unlock sort of level selector. If the level is locked the button is disable and not show. When you succeed a level, the next level (button) appears and it’s clickable.

In my design i have some levels who can unlock multiple level (like from a city you can go to mountain level or ocean level so there is 2 way).
I have 2 solution :
Make trigger so when a level is win i define a method in each level to tell wich level is now unlocked.
Or i make a more generic solution who detect the nearest buttons on the way.

I have a solution where an entity, after a victory is going to follow the path2D in every direction from the position i’m at. If it detect an unlock button it stops, if it detect a locked buttons it unlocked it and stop and i will “fire” entity to like all the direction on my map.
I think this will works but i know it’s not the best solution and i’m not so familiar with godot objects.
I don’t know if you can create child in a path2D and interact easily with those in a script or no ?

Your help is really helpful and if you have any questions to clarify the subject (english is not my first language :/) let me know.

Have a great day !

:bust_in_silhouette: Reply From: happycamper

Probably your first solution is the best way to go about it. Create an array of “available_levels” so you know which levels are unlocked. You could also create a dictionary that tells you which level unlocks which other levels instead of having to create a unique function for each finished level, that way its easy to add to your available_levels array using the dictionary.

Thanks for the response, i’m not quite use to dictionnary but I’m going to do this the time i figure an other solution because it’s clean.

But in many games like Skyrim, Final Fantasy you have this lock/unlock system (with Skill Trees etc…) I’m pretty sure there is a more generic way to do this so i can expand my levels just in adding a new buttons and it will works…

tomandrieu | 2018-06-27 10:58