# Legacy GMRTS unit position after movement

#### Shavv

##### Member
Heey guys, i need some help. After i make my units order to move i want them to have a formation. But im having trouble creating a formation. I could make the formation with hand and assign each unit number to a position one by one, but having over 100 units would be a huge task.

So i wanted to know if there is a math equation to this outcome i want to have.

I also saw some other post with a similiar-ish problem but wasn't really helpfull.

Code:
``````if selected=true
{
if mouse_check_button_pressed(mb_right)
{
walkx=mouse_x
walky=mouse_y
}
}

if state=0
{
if distance_to_point(walkx,walky)>1
{
mp_potential_step_object(walkx,walky,movespeed,SOLID)
if xprevious<x {image_xscale= 1}
if xprevious>x {image_xscale=-1}
}
}``````

#### Smiechu

##### Member
When you make a selection, make one of the units a "leader". Leader will get a list of units within selection.
Than, your orders are passed only to the leader, and the leader passes the order to all other units form the list with checking their relative position.
Later in this approach you can define how the formatiom should behave, i.e. turn the formation in the direction of movement...

Rob

#### Shavv

##### Member
I tried something like that, but didnt seem to work for me (probably did it wrong hence why im here) because the position i got out of it made them make a diagnal line

#### Morendral

##### Member
I tried something like that, but didnt seem to work for me (probably did it wrong hence why im here) because the position i got out of it made them make a diagnal line
In that case you just need to change the code that assigned the relative positions. Post that code and we can try to help with it. I've done this exact thing myself before.

#### Jdown79

##### Member
Isn't the issue here that all of your soldiers are trying to go into the space of one?

#### Niels

##### Member
Looks like every soldier is moving towards the same position..
The target position should have a grid with the offset of every soldier.
For example:

XXX ====> XXX

XXX===> X

#### GMWolf

##### aka fel666
Two options:
1: keep exact formation.
When you give a movement order, find the average position of all selected units.
Each unit then finds the offset from that center point. They will then navigate towards the target point, plus that offset.

2: new formation
When giving an order, make a list of all selected units. Then, use that list to give each unit a new position.
Look at div and mod to go from the list index, to a position in a grid.