[solved] How to move squad units together

Here’s my problem of the day:


I need to always assign the position of a team leader to an instance variable of its nonleader friends so they can pathfind to him when needed, the problem being that there are [0-9] teams.

Long version:
I’m making a war game prototype.
I spawn through events a random number of squads of 3 units.
In each team, there is one leader identified by a Leader instance variable.
Everyone has a Team instance variable to know with who they belong.
I want nonleader units to place themselves behind the leader when the player chooses to do so, using pathfinding.
I succeeded with one team, but I’m stuck with several teams.
I need to do: for each non leader soldier, if left is pressed, move soldier to soldier.Variable(FollowTheLeader.X/Y)
But how do I assign the current X position of one specific instance to a variable of another specific instance? :confused:

I wonder if creating a Leader object might help…

Well, the solution was the same as last time, the brackets, as explained here:
http://wiki.compilgames.net/doku.php/gdevelop5/all-features/variables#dynamic_access_to_the_children
These brackets give me such a hard time :sweat_smile:
Problem solved. :slight_smile:

2 Likes