• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Unit turns backwards unexpectedly in the middle of dash/running ability

Level 3
Joined
Jun 6, 2024
Messages
12
I'm trying to create a skill where the hero charges in a straight line (it is a target point ability), moving at super fast speed, dealing damage and stunning every unit in his line. The charge will advance up to a distance of 1400 unless the user cancels it by giving an order. It can keep going (surpassing the 1400 distance) if the unit is on a cliff at that moment (a unique square region in my map, so it is easily detectable). No unit can go over a cliff except for this unit while executing this ability (because I will turn off collisions).

The problem is that I encounter (maybe a bug?) an unexpected behavior where the unit turns backwards at some point while the trigger "running" move the unit. It doesn't occur always at the same point; it seems to be some kind of random behavior.

Sadly, I can't keep trying anything until I resolve this. Maybe I'm approaching this the wrong way. Any help, please?


  • onslaught starts
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Set Magna = (Triggering unit)
      • Set Point_A = (Position of (Triggering unit))
      • Set Point_B = (Target point of ability being cast)
      • Set Angle = (Angle from Point_A to Point_B)
      • Set final_destination = (Point_A offset by 1400.00 towards Angle degrees)
      • Wait 1.00 seconds
      • Unit - Turn collision for Magna Off
      • Animation - Change Magna's animation speed to 200.00% of its original speed
      • Unit - Order Magna to Move To final_destination
      • Trigger - Turn on running <gen>
      • Wait 4.00 seconds
      • Animation - Change Magna's animation speed to 100.00% of its original speed
      • Unit - Turn collision for Magna On
      • Trigger - Turn off running <gen>

  • running
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Custom script: call SetUnitX( udg_Magna , GetLocationX(GetUnitLoc( udg_Magna )) + 10 )
I'm aware of all the hardcoded things in those triggers, but that doesnt explain why the unit turns around while the trigger "running" is running.
 

Attachments

  • magnarun_demo.w3x
    18 KB · Views: 6

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Just going to list a few mistakes or possible issues I see, maybe you're aware already so feel free to ignore this.

This line here:
  • Custom script: call SetUnitX( udg_Magna , GetLocationX(GetUnitLoc( udg_Magna )) + 10 )
Can be changed to this:
  • Custom script: call SetUnitX( udg_Magna , GetUnitX( udg_Magna ) + 10 )
You don't need to create a Point at the unit's position then get the X coordinate of that Point when you can just get the unit's X coordinate directly.

But there's a bigger problem. This SetUnitX() function always moves the unit towards the right side and has no relation with final_destination.

If you wanted to move the unit towards final_destination you would use the Point With Polar Offset function to determine the next Point. Then you can use SetUnitX and SetUnitY to reposition the unit there:
  • Actions
    • Set P[1] = (Position of Magna)
    • Set P[2] = (P[1] offset by 10.00 towards Angle)
    • Custom script: call SetUnitX( udg_Magna , GetLocationX( udg_P[2] ) )
    • Custom script: call SetUnitY( udg_Magna , GetLocationY( udg_P[2] ) )
    • Custom script: call RemoveLocation( udg_P[1] )
    • Custom script: call RemoveLocation( udg_P[2] )
I also addressed the Point (location) memory leaks. None of this is MUI/MPI and will break if more than one unit has this ability.

Lastly, you can rely on different methods to prevent the unit from going over cliffs and getting stuck. For example, there are systems to check if a Point is pathable, which you would use in your running trigger before moving the unit -> If P[2] is pathable then call SetUnitX/Y. These tricks often rely on a hidden Item since that can be used to test different kinds of pathing. You would choose a Point where you want to test pathing, then move the Item there, then make a distance comparison to see how far the Item is from the Point. If it moved far enough away then you can assume that the Point was unpathable. This works because Warcraft 3's built in "collision system" will force the Item to reposition to the nearest pathable Point. I believe Items cannot be placed on: Deep water, Cliff edges, Buildings, Destructables, and any Ground pathing blocker for that matter.
 
Last edited:
Level 3
Joined
Jun 6, 2024
Messages
12
Just going to list a few mistakes or possible issues I see, maybe you're aware already so feel free to ignore this.

This line here:
  • Custom script: call SetUnitX( udg_Magna , GetLocationX(GetUnitLoc( udg_Magna )) + 10 )
Can be changed to this:
  • Custom script: call SetUnitX( udg_Magna , GetUnitX( udg_Magna ) + 10 )
You don't need to create a Point at the unit's position then get the X coordinate of that Point when you can just get the unit's X coordinate directly.

But there's a bigger problem. This SetUnitX() function always moves the unit towards the right side and has no relation with final_destination.

If you wanted to move the unit towards final_destination you would use the Point With Polar Offset function to determine the next Point. Then you can use SetUnitX and SetUnitY to reposition the unit there:
  • Actions
    • Set P[1] = (Position of Magna)
    • Set P[2] = (P[1] offset by 10.00 towards Angle)
    • Custom script: call SetUnitX( udg_Magna , GetLocationX( udg_P[2] ) )
    • Custom script: call SetUnitY( udg_Magna , GetLocationY( udg_P[2] ) )
    • Custom script: call RemoveLocation( udg_P[1] )
    • Custom script: call RemoveLocation( udg_P[2] )
I also addressed the Point (location) memory leaks. None of this is MUI/MPI and will break if more than one unit has this ability.

Lastly, you can rely on different methods to prevent the unit from going over cliffs and getting stuck. For example, there are systems to check if a Point is pathable, which you would use in your running trigger before moving the unit -> If P[2] is pathable then call SetUnitX/Y. These tricks often rely on a hidden Item since that can be used to test different kinds of pathing. You would choose a Point where you want to test pathing, then move the Item there, then make a distance comparison to see how far the Item is from the Point. If it moved far enough away then you can assume that the Point was unpathable. This works because Warcraft 3's built in "collision system" will force the Item to reposition to the nearest pathable Point. I believe Items cannot be placed on: Deep water, Cliff edges, Buildings, Destructables, and any Ground pathing blocker for that matter.

First of all, thank you Uncle for all the pointers! And sorry for the late response, I had a very busy week.

I didn't know that I could get the X position directly from the unit. Shorter and more efficient, thanks!

Yes I was aware that I was always moving to the right. I was just starting and needed to test if the thing I was trying to do could work. I'm just a noob, so any hint is appreciated!

BTW "(P[1] offset by 10.00 towards Angle)" is a very convenient way to get the next point. Even though I used that previously I think I would have missed it, so thanks again!

Regarding going through cliffs, that is not an issue in my case because I want the unit to go through cliffs. However, I will investigate pathing blockers for certain regions of my map that shouldn't be traversed in any way (can they be placed in the UI Editor or only through triggers?).

Is ordering the unit to move while I increase the speed by displacing it with SetX/SetY a good approach, or should I move the unit only with SetX/SetY? I was using the order "move" to "smooth" the movement a bit, although I don't know if it is noticeable.

The problem that I'm having is that the "walk fast" animation is not being played (or any animation for that matter). I don't know the reason for this. I tried with Queue and Play; none of them seem to work... I'm very confused about this.

Thanks again, I appreciate any help to complete this skill :)
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Regarding going through cliffs, that is not an issue in my case because I want the unit to go through cliffs. However, I will investigate pathing blockers for certain regions of my map that shouldn't be traversed in any way (can they be placed in the UI Editor or only through triggers?).
I'm not sure what the UI Editor is but you can place Pathing Blockers in the World Editor, they're nothing more than Destructables.

Is ordering the unit to move while I increase the speed by displacing it with SetX/SetY a good approach, or should I move the unit only with SetX/SetY? I was using the order "move" to "smooth" the movement a bit, although I don't know if it is noticeable.
Those slide maps rely on a combination of unit movement + x/y displacement, it's a nice effect for bypassing the 522 movement speed limit. But if your dash ability is meant to be uncontrollable while active then I would simply disable the unit during it.

What I do for my movement skills is run my movement logic in a 0.02 second interval. Then during the very first "movement cycle" I disable the unit. Then I enable it once the skill is finished. But you're on an older version so your options to disable it are limited. I would try to avoid the Pause action, ideally you could Stun the caster with a Dummy unit using Storm Bolt.
 
Last edited:
Level 3
Joined
Jun 6, 2024
Messages
12
Thank you all! I think I almost have it done. I endup doing that Uncle. I paused the unit while inside the cliff and unpause it when it goes off. That already solved my problem. The only thing left is something like a bug, because I can recast the skill (it's even detected by the event triggers) by just right-clicking the ground after the skill finishes, even though the ability (based on Channel) is on cooldown. I'm totally puzzled by this. I think I can work around this by using a timer to simulate the cooldown and prevent the execution of the triggers if it's on cooldown. But it's really strange. If I can't find the reason for this problem, I will use timers and flags to prevent the relaunch of the skill.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Thank you all! I think I almost have it done. I endup doing that Uncle. I paused the unit while inside the cliff and unpause it when it goes off. That already solved my problem. The only thing left is something like a bug, because I can recast the skill (it's even detected by the event triggers) by just right-clicking the ground after the skill finishes, even though the ability (based on Channel) is on cooldown. I'm totally puzzled by this. I think I can work around this by using a timer to simulate the cooldown and prevent the execution of the triggers if it's on cooldown. But it's really strange. If I can't find the reason for this problem, I will use timers and flags to prevent the relaunch of the skill.
Sounds like an issue with Pause, which is why I said I'd avoid using it. Pause has a lot of unwanted side effects. Also, interrupting a unit in response to certain Events will cause unwanted side effects as well. For example, interrupting an ability during the Starts Effect stage can bypass the mana cost, cooldown, etc.
 
Top