• 🏆 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!

One unit following another problem

Status
Not open for further replies.
Level 6
Joined
Jul 22, 2021
Messages
50
Hello,

So I've got this problem where I want one unit to follow the another, and at the same time make it stay close to each other.
I tried manipulating various stats in unit editor (collision size, movement types, etc.) and the problem persists. In my view, it occurs mainly when there are doodads nearby or height of terrain change.
Below are graphic examples of how it should be at all times and what happens when something is wrong (it either stops or lags behind).
good.png
bad.png

What makes the wagon follow the horse is this trigger:
  • FollowPackHorse
    • Events
      • Time - Every 0.00 seconds of game time
    • Conditions
    • Actions
      • Unit - Order Wagon 0182 <gen> to Follow Dolly (slow) 0183 <gen>
I want it to make one unit follow another, because later on I want to make "defend caravan" follow up.

Any ideas, or tips?

Thanks in advance!
 
Level 19
Joined
Feb 27, 2019
Messages
590
I dont see how making an order every 0.00 seconds helps. In my experience setting orders often only slows units. Have you tried setting the wagons movement speed greater than the horses and reduce the amount of orders given?

Another option is to move the wagon to a point behind the horse and set its facing every 0.03 seconds. I think something like this is what you are looking for. It might "swing" a lot from side to side if the horse turns around though.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,542
In the Gameplay Constants you can define Unit - Follow Range and adjust how close units get to one another.

Alternate solutions:
Periodically order the wagon to move to the position behind the mule.
Periodically use Move Unit instantly to position the wagon behind the mule and use Set unit facing immediately to get the facing correct.
 
Level 6
Joined
Jul 22, 2021
Messages
50
Have you tried setting the wagons movement speed greater than the horses and reduce the amount of orders given?
Yes, I did try that.

After many iterations, I reached a satisfying result.
I messed around with movement minimum/maximum speed, collision size or movement type.

I changed the trigger to the following:
  • FollowPackHorse
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit - Order Wagon 0182 <gen> to Move To ((Position of Dolly (slow) 0183 <gen>) offset by (0.00, -30.00))
      • Wait 0.04 seconds
      • Unit - Make Wagon 0182 <gen> face Dolly (slow) 0183 <gen> over 0.00 seconds
There is a room for improvement still but as I already said - result is good enough.

Thanks.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,542
Yes, I did try that.

After many iterations, I reached a satisfying result.
I messed around with movement minimum/maximum speed, collision size or movement type.

I changed the trigger to the following:
  • FollowPackHorse
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit - Order Wagon 0182 <gen> to Move To ((Position of Dolly (slow) 0183 <gen>) offset by (0.00, -30.00))
      • Wait 0.04 seconds
      • Unit - Make Wagon 0182 <gen> face Dolly (slow) 0183 <gen> over 0.00 seconds
There is a room for improvement still but as I already said - result is good enough.

Thanks.
To prevent a lot of memory leaks:
  • Set Variable WagonPointA = Position of Dolly (slow)
  • Set Variable WagonPointB = WagonPointA offset by (0.00, -30.00)
  • Unit - Order Wagon to Move to WagonPointB
  • Custom script: call RemoveLocation(udg_WagonPointA)
  • Custom script: call RemoveLocation(udg_WagonPointB)
  • Wait 0.04 seconds
  • Unit - Make Wagon 0182 <gen> face Dolly (slow) 0183 <gen> over 0.00 seconds
Also, if your mule were to travel south then the Wagon would try to get in front of it since you're using Point with Offset which works on X/Y coordinates. So using -30.00 as your Y coordinate will always result in south of the Wagon regardless of which direction it's facing.

To get the correct position in any given situation:
Store the Position of each unit in their own Point variables.
Get the Angle between these two Points and store it in a variable.
Remove the Wagon's Point variable as it's no longer needed and will become a memory leak if we don't.
Using Point with Polar Offset, reference the Mule's Point variable offset by 30.00 towards the Angle, and store this in a new Point variable.
Order the Wagon to move to this new Point.
Remove the Mule Point variable and the new Point variable.
 
Last edited:
Status
Not open for further replies.
Top