• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How to make a unit walk to a point next to another unit?

Status
Not open for further replies.
Level 6
Joined
Dec 8, 2009
Messages
179
Hi everyone,

I got a smaller problem making a unit group follow a single unit.
the group should not receive a "follow unit" - order I want them to
walk to a specific point in some small distance behind the unit they should follow.
I now don`t now how to define that point behind the unit in GUI.
 
Level 13
Joined
Jun 22, 2004
Messages
783
What you need, is a unit group in which your following units are stored.

So ill give you the action first, then some more instructions on making it leak free, and last but not least, giving it a conditional statement to make sure they don't keep on moving when they are in range of the unit they are following.

First we'll need a new trigger to let the following units follow the target,
We'd want to use a event, that runs every 1 second (this to make sure they are at least ordered once a second to follow the target)

Next up is making an action that would order all the units in this following unit group you made to have them follow the target, so we use the following action to refer to the units inside a group:
Unit Group - Pick Every Unit in A Unit Group and do Multiple Actions
we fill in the unit group we have made in which the unit are stored.
now we'll have to construct a unit order for each of the units inside the unit group.
Unit - Issue Order Targeting A Point
we choose picked unit for which unit, and for the last chunk we choose the option "Point with Polar Offset" (this the distance and angle from a certain point).

For the point itself, we use "Position of Unit" and we pick the possition of the unit we'd want to follow (or the variable if you saved the unit in a variable).
for the distance(real), you'd want to fill out the distance that they want to be ordered to away from the unit the follow(I choose 150).
last but not least is the angle value, we'd want to use a Arithmetic
you'll see 1.00 + 1.00.
For the first 1.00 we'd want to select the angle of the unit they are following,
for the second 1.00 you fill in 180.
Now they are ordered to a position behind the unit they are following.
The trigger looks like this.

  • You Trigger Name
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in "Your unit group" and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Move To ((Position of "your Unit that need to be followed"<gen>) offset by 100.00 towards ((Facing of "your Unit that need to be followed"<gen>) + 180.00) degrees)
Well to make it leak free you should make 3 new variables (2 point variables and 1 unit group variable)
first the unit group variable, cause you already have a original group, we need to make sure you don't remove the content of the unitgroup like so
Code:
tempgroup = "your following group"
this would remove the content of the following group as well, so we need to only check the content.
  • Set tempgroup = (Units in (Entire map) matching (((Matching unit) is in "your unit group") Equal to True))
next we need 2 point variables, one for the position of the unit the need to follow and another for the offset from the following unit, this would look like the following.

  • Set temppoint0 = (Position of "your unit"<gen>)
  • Set temppoint1 = (temppoint0 offset by 150.00 towards ((Facing of "your unit"<gen>) + 180.00) degrees)
so basically what we did is put the content of the points in our previous action, in variables to temporarily save them, and after we used it we want to remove it, so the final trigger leak free would look like this.

  • follow
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set tempgroup = (Units in (Entire map) matching (((Matching unit) is in "unit group") Equal to True))
      • Unit Group - Pick every unit in tempgroup and do (Actions)
        • Loop - Actions
          • Set temppoint0 = (Position of "your unit"<gen>)
          • Set temppoint1 = (temppoint0 offset by 150.00 towards ((Facing of "your unit" <gen>) + 180.00) degrees)
          • Unit - Order (Picked unit) to Move To temppoint1
          • Custom script: call RemoveLocation (udg_temppoint0)
          • Custom script: call RemoveLocation (udg_temppoint1)
      • Custom script: call DestroyGroup (udg_tempgroup)
Last but not least, a small conditional statement to check if they are already in range (cause if they are we don't want to give them a new order).

We'd have to place a condition inside the loop to make sure that each unit is individually checked, so a good condition to check is the distance between 2 points, that falls under "Real Comparison".

Would look like this.
  • (Distance between (Position of "your unit"<gen>) and (Position of (Picked unit))) Greater than 150.00
Now we check if each picked unit inside your unitgroup has a greater distance then 150, if it has, than we need to run actions, if not, we don't.
So the final trigger would look like the following.

  • follow
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set tempgroup = (Units in (Entire map) matching (((Matching unit) is in "your unitgroup") Equal to True))
      • Unit Group - Pick every unit in tempgroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between (Position of "your unit"<gen>) and (Position of (Picked unit))) Greater than 150.00
            • Then - Actions
              • Set temppoint0 = (Position of "your unit"<gen>)
              • Set temppoint1 = (temppoint0 offset by 150.00 towards ((Facing of Peasant 0000 <gen>) + 180.00) degrees)
              • Unit - Order (Picked unit) to Move To temppoint1
              • Custom script: call RemoveLocation (udg_temppoint0)
              • Custom script: call RemoveLocation (udg_temppoint1)
            • Else - Actions
      • Custom script: call DestroyGroup (udg_tempgroup)
Hope this works for you and is what you are looking for.
Good luck
 
Status
Not open for further replies.
Top