Move units to another unit w/o losing their formation

Eimtr

Member
Reaction score
1
[SOLVED] Move units to another unit w/o losing their formation

Looks like my last question with WE cause im soon done with it and war3. Then we will see how harder is SC2Editor is compared to sc2 beta.

I have a group of units in an army formation, close to each other. I want every 0.01 second to move them instantly to position of another unit. The problem is that if I Pick them and move them instantly they all are moved to the same point thus 10 units are pushed in1 point looking like one.

I want to move them to the position of the other unit instantly and keep their formation, not move them all at 1 point. But the object to which I'm moving them is also moveable so using a point on the map wont help as they always should be at the position of that other object that is also moving.

it's like I need to move them in the same way when you select more units in the editor and move them, they keep their formation/order
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
instead of picking all units and issueing them the move order individually pick the whole group of them and issue that order to the group. but keep in mind you can only issue orders to groups of the size of 12 units or below.

Trigger:
  • Unit Group - Order (Units in (Playable map area)) to Move to (Center of (Playable map area))
 

Eimtr

Member
Reaction score
1
The thing is I dont want them to walk as this would look unrealistic. That's why Im using the 'Move instantly' not order to move and just remain with some distance between them, that is their formation. As I said, I need to keep their distance not just make them move at the same point.
 

Ashlebede

New Member
Reaction score
43
This is approximate ; they will keep their formation, but they might not end up exactly at the place where you want them to. Make sure there is plenty of space for them to land onto.

Trigger:
  • //Hand-written
    • -------- Requires two point-type variables, a unit group-type variable and 2 real-type variables --------
    • Set group = {Group}
    • Set point1 = Position of (Random unit from group)
    • Set point2 = {Target Point}
    • Set EstimatedDistance = Distance between point1 and point2
    • Set EstimatedAngle = Angle between point1 and point2
    • Custom Script : call RemoveLocation(udg_point1)
    • Custom Script : call RemoveLocation(udg_point2)
    • -------- If you want to destroy the group, use this line : --------
    • Custom Script : set bj_wantDestroyGroup = true
    • Unit Group - For each unit in group, do (Loop actions)
      • Loop - Actions
        • Set point1 = Position of (Picked unit)
        • Set point2 = point1 offset by EstimatedDistance towards EstimatedDegrees [Point with polar offset]
        • Unit - Move (Picked unit) to point2 (instantly)
        • Custom Script : call RemoveLocation(udg_point1)
        • Custom Script : call RemoveLocation(udg_point2)


Edit : Oh, and I saw you wanted to do that every .01 seconds. That is too much, most definitely. Maybe it's because my computer is really bad, but performance has always been a top priority to me. Those who want best effect for "frame-per-frame" animations use .03 delay. I usually use .04.
 

Eimtr

Member
Reaction score
1
I decided that it is better if they stand in a circle in some range from the Main unit. When I use the below triggers to move every 0.01 sec each of the units to form a circle around the main unit so that when the main is moving they also move - it works.

PROBLEMs:
- this trigger causes lag after the 3rd minute so I need an alternative of it that isnt laggy but you get what im trying to do
- Even if I make the circle and they stand attached to the main unit like that, whenever the Main unit rotates/turns on a direction, they do not rotate because they are placed at degrees in general but I need to make the degrees towards the facing of the Main unit,


Trigger:
  • Test2
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Unit - Move Marine 0003 <gen> instantly to ((Position of (Random unit from (Units of type Main Unit))) offset by 320.00 towards 30.00 degrees)
      • Unit - Move Terran Medic 0010 <gen> instantly to ((Position of (Random unit from (Units of type Main Unit))) offset by 320.00 towards 60.00 degrees)
      • Unit - Move Marine 0007 <gen> instantly to ((Position of (Random unit from (Units of type Main Unit))) offset by 320.00 towards 90.00 degrees)
      • Unit - Move Marine 0004 <gen> instantly to ((Position of (Random unit from (Units of type Main Unit))) offset by 320.00 towards 120.00 degrees)
      • Unit - Move Marine 0013 <gen> instantly to ((Position of (Random unit from (Units of type Main Unit))) offset by 320.00 towards 150.00 degrees)
      • Unit - Move Marine 0012 <gen> instantly to ((Position of (Random unit from (Units of type Main Unit))) offset by 320.00 towards 180.00 degrees)
      • Unit - Move Terran Medic 0009 <gen> instantly to ((Position of (Random unit from (Units of type Main Unit))) offset by 320.00 towards 210.00 degrees)
      • Unit - Move Marine 0006 <gen> instantly to ((Position of (Random unit from (Units of type Main Unit))) offset by 320.00 towards 240.00 degrees)
      • Unit - Move Terran Medic 0011 <gen> instantly to ((Position of (Random unit from (Units of type Main Unit))) offset by 320.00 towards 270.00 degrees)
      • Unit - Move Marine 0008 <gen> instantly to ((Position of (Random unit from (Units of type Main Unit))) offset by 320.00 towards 300.00 degrees)
      • Unit - Move Terran Medic 0015 <gen> instantly to ((Position of (Random unit from (Units of type Main Unit))) offset by 320.00 towards 330.00 degrees)
      • Unit - Move Marine 0014 <gen> instantly to ((Position of (Random unit from (Units of type Main Unit))) offset by 320.00 towards 360.00 degrees)
 

Ashlebede

New Member
Reaction score
43
Your trigger is leaking points. Replace a unit movement with :

Trigger:
  • //Hand-written
    • Set point1 = Position of {Unit}
    • Set point2 = point1 offset by {...}
    • Unit - Move {...}
    • Custom Script : call RemoveLocation(udg_point1)
    • Custom Script : call RemoveLocation(udg_point2)


That frees some memory space, allowing better long-term performance. Also, use .03 delay instead of .01, once again.
 

Eimtr

Member
Reaction score
1
This worked, thanks. But this solves the lag problem, at least now it seems to be OK. Problem 2 that has to do with the degree - now that I made the circle of units around the Main Unit, whenever I move the Main Unit on the map, it turns direction and when it turns direction, the circle of 12 units doesn't turn. So how do I make these degrees based on the Main unit's facing so that when it turns, the 12 units also turn side (not their facing but say a unit is at 12 0'clock and the front side of the Main unit too, when the front side of Main Unit turns left the unit at 12 o'clock should also turn left and the rest of the units based on the Main Unit facing)

Trigger:
  • Test
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Set MainUnitPoint = (Position of (Random unit from (Units of type Domed Space Platform)))
      • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 30.00 degrees)
      • Unit - Move Marine 0003 <gen> instantly to MainUnitUnitPoint
      • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 60.00 degrees)
      • Unit - Move Marine 0004 <gen> instantly to MainUnitUnitPoint
      • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 90.00 degrees)
      • Unit - Move Marine 0006 <gen> instantly to MainUnitUnitPoint
      • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 120.00 degrees)
      • Unit - Move Marine 0007 <gen> instantly to MainUnitUnitPoint
      • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 150.00 degrees)
      • Unit - Move Marine 0008 <gen> instantly to MainUnitUnitPoint
      • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 180.00 degrees)
      • Unit - Move Marine 0012 <gen> instantly to MainUnitUnitPoint
      • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 210.00 degrees)
      • Unit - Move Marine 0013 <gen> instantly to MainUnitUnitPoint
      • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 240.00 degrees)
      • Unit - Move Marine 0014 <gen> instantly to MainUnitUnitPoint
      • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 270.00 degrees)
      • Unit - Move Terran Medic 0009 <gen> instantly to MainUnitUnitPoint
      • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 300.00 degrees)
      • Unit - Move Terran Medic 0010 <gen> instantly to MainUnitUnitPoint
      • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 330.00 degrees)
      • Unit - Move Terran Medic 0011 <gen> instantly to MainUnitUnitPoint
      • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 360.00 degrees)
      • Unit - Move Terran Medic 0015 <gen> instantly to MainUnitUnitPoint
      • Custom script: call RemoveLocation(udg_MainUnitPoint)
      • Custom script: call RemoveLocation(udg_MainUnitUnitPoint)
 

Ashlebede

New Member
Reaction score
43
One note : you have to remove the [ljass]MainUnitUnitPoint[/ljass] every time you give it a new value. The first few lines would become :

Trigger:
  • //Hand-written
    • Set MainUnitPoint = (Position of (Random unit from (Units of type Domed Space Platform)))
    • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 30.00 degrees)
    • Unit - Move Marine 0003 <gen> instantly to MainUnitUnitPoint
    • Custom Script : call RemoveLocation(udg_MainUnitUnitPoint)
    • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 60.00 degrees)
    • Unit - Move Marine 0004 <gen> instantly to MainUnitUnitPointSet
    • Custom Script : call RemoveLocation(udg_MainUnitUnitPoint)
    • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards 90.00 degrees)
    • Unit - Move Marine 0006 <gen> instantly to MainUnitUnitPoint
    • Custom Script : call RemoveLocation(udg_MainUnitUnitPoint)
    • -------- And so on... --------


Just noticed there is also a unit group leak. It's about the same as with locations :

Trigger:
  • //Hand-written
    • Set MyUnitGroup = {...}
    • Set MainUnitPoint = (Position of (Random unit from MyUnitGroup))
    • Custom Script : call DestroyGroup(udg_MyUnitGroup)


And if I got what you mean, your angle should just depend on the facing of the main unit.

Trigger:
  • //Hand-written
    • Set MainUnitPoint = {...}
    • Set MainUnitFacing = Facing of ({Main unit})
    • Set MainUnitUnitPoint = (MainUnitPoint offset by 320.00 towards (MainUnitFacing+30.00) degrees)
    • -------- And so on... --------
 

Eimtr

Member
Reaction score
1
I decided to have them in a separate trigger for each unit as I am going to turn them off on some occassions and I did add those custom scripts:

Trigger:
  • DSPMedic011
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Set DSPGroup = (Units of type DSP)
      • Set DSP = (Position of (Random unit from DSPGroup))
      • Set DSPFacing = (Facing of (Random unit from DSPGroup))
      • Set DSPPoint = (DSP offset by 320.00 towards (DSPFacing + 330.00) degrees)
      • Unit - Move Terran Medic 0011 <gen> instantly to DSPPoint
      • Custom script: call DestroyGroup(udg_DSPGroup)
      • Custom script: call RemoveLocation(udg_DSP)
      • Custom script: call RemoveLocation(udg_DSPPoint)


etc. And yes I meant to rotate along with the main unit, so what you told me works. Thx for the help +rep
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top