• 🏆 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!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!

How do you make AI randomly follow units?

Not open for further replies.
Level 20
Feb 24, 2009
Good question, the solutions aren't hard, but they're many.
The simplest thing to do would be something like this:

  • Melee Initialization
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area) owned by GhostAI) and do (Actions)
        • Loop - Actions
          • Set tmp_unit = (Random unit from (Units in (Playable map area) matching ((Owner of (Matching unit)) Not equal to GhostAI)))
          • Unit - Order (Picked unit) to Attack tmp_unit
          • Custom script: call RemoveUnit(udg_tmp_unit)
You can change the timer value, to keep them chasing after the same person longer.

This is nice and simple, it has it's problems. For e.g. if a unit kills the one it's following you may find it sat still for several seconds before the trigger runs again, neither does it check to see if the ghost has nearly caught a unit, a simple condition along the lines of if units are within x of picked unit would solve that though.

If this isn't quite good enough for you feel free to post back with some more detail on what you want it to do and I'd be happy to assist you further :)
Not open for further replies.