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

Simplest Detect Movement/Walking

Status
Not open for further replies.
SIMPLEST Detect Movement/Walking Checker



Did you ever wonder if you were moving? Here's a super simple way to know for sure.

  • Detect walking
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • b Equal to True
        • Then - Actions
          • Set b = False
          • Custom script: call RemoveLocation(udg_point[1])
          • Set point[1] = (Position of unit)
        • Else - Actions
          • Set b = True
          • Custom script: call RemoveLocation(udg_point[2])
          • Set point[2] = (Position of unit)
      • Set WalkDistance = (Distance between point[1] and point[2])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WalkDistance Greater than or equal to 1.00
        • Then - Actions
          • Set IsMoving = True
        • Else - Actions
          • Set IsMoving = False
There are complex versions of this out there. This is for people who don't have time for that.

It can be used as a condition to stop a movement sound or animation. Or ... it could be an event like this:

  • You're Really Moving Now
    • Events
      • Game - WalkDistance becomes Greater than or equal to 1.00
 
Last edited:
This is also the version for those people who don't care about accumulating thousands of leaks.

Please, for the love of god, use reals for X and Y coordinates instead of locations. It also makes the distance check redundant, as you can simply check if the last X/Y and the new X/Y are the same or not.
Fixed the leaks.
Ok, that's true about x,y but it is the same concept. Using x,y is a better method.
That was actually my inspiration. I wanted it but it was a bit more complex than what I needed. This is the most rudimentary form of movement detection. It's more for people to learn the basics. Of course, there are several better versions available.
and Im just sitting here, waiting for a proper snippet which would detect movement event without being fired when various triggered relocations happens
What a co-inky-dink, me too. I looked everywhere last night for one, then I had to write my own. Obviously, someone could use this if they could ever find the lab, but most people probably will never need this. Does it offend you somehow?
What about checking the current order of the unit?
Great question, I am glad you asked. See, I was just checking for the order, but then the unit would run into a barrier and the run animation and footstep sound kept playing. This snippet is to detect actual movement. Sometimes the "current order" is 'smart' or 'move' but the unit isn't going anywhere. This let's you know when it is actually moving. Also, if you use a knockback and you want to know when to stop pushing a unit, this helps to stop trying to move a unit up against a cliff. Sure, most knockbacks are quite advanced at this point, but the concept is still useful. This is a starting point for people looking for direction. Like I was last night. I wish I had found this instead of wasting an hour looking and 15 minutes writing this overly simple (yet useful) bit of code.

Here's what I needed it for:

  • Walk Anmiation Sound
    • Events
    • Conditions
    • Actions
      • Set CurrentOrder = (Current order of unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • CurrentOrder Equal to (Order(move))
              • CurrentOrder Equal to (Order(smart))
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IsMoving Equal to True
            • Then - Actions
              • Set Standing = False
              • Sound - Stop step <gen> Immediately
              • Sound - Play step <gen>
              • Animation - Change unit's animation speed to 125.00% of its original speed
            • Else - Actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current order of unit) Equal to (Order(<Empty String>))
              • Standing Equal to False
              • IsMoving Equal to False
            • Then - Actions
              • Sound - Stop step <gen> Immediately
              • Set Standing = True
              • Animation - Change unit's animation speed to 777.00% of its original speed
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (unit has an item of type Lion Shield) Equal to False
                • Then - Actions
                  • Custom script: call SetUnitAnimationByIndex( udg_unit , 2 )
                • Else - Actions
                  • Custom script: call SetUnitAnimationByIndex( udg_unit , 0 )
              • Wait 0.02 seconds
              • Animation - Change unit's animation speed to 0.00% of its original speed
            • Else - Actions
 
Level 7
Joined
Oct 19, 2015
Messages
286
Your "simple" version is still needlessly complicated.
  • Detect walking
  • Events
  • Time - Every 0.03 seconds of game time
  • Conditions
  • Actions
  • Set point[2] = point[1]
  • Set point[1] = (Position of unit)
  • Set WalkDistance = (Distance between point[1] and point[2])
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • WalkDistance Greater than or equal to 1.00
    • Then - Actions
      • Set IsMoving = True
    • Else - Actions
      • Set IsMoving = False
  • Custom script: call RemoveLocation(udg_point[2])
Also ,as already noted, it should really use x/y instead of locations, it should support more than a single unit, really it should just be written in (v)jass.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Differentiate between whether a unit is moving by script or order. With just an IsUnitMovement, the thing is nearly useless. If you want to use it for something like stamina, you don't want to reduce stamina when they cast a spell like Blink or are moved by scripts from something like knockback.


Another thing that's important is supporting events. When does a unit begin moving? When does a unit stop moving? Users aren't going to read IsUnitMoving for every unit in the map every period. That's silly. They're going to latch on to these events and put them into lists.


Yea, you can detect whether a unit is moving or not pretty easily with GetUnitX and GetUnitY, but that by itself is not necessarily useful. It's all of the other features that use that as a core that are useful : ).


A snippet like this is easy enough for anyone to figure it out on their own ^)^. Figuring out the things that can go wrong with it and what needs to be supported in order for it to be useful are another story : ).


I also don't know about firing an event every time movement occurs on a period. It would be cool if triggers ran as quickly as functions. That's why the other libs opted for lists.
 
Level 5
Joined
Mar 6, 2015
Messages
130
I`m Using the System which was came with Bribe`s DDS i think it`s name is " IS Unit Moving" it has it`s own Event very easy to use it is MUI , you can change it`s code a little bit for some special circumstances like adding a boolean as a flag to system to determine whether unit is walking or it just getting knockbacked the system`s code itself is more complex than yours but its 100% working and its very easy to use EventMoving =1 means moving and Eventmoving = 2 means stoped moving :D it`s more Efficient to use this system over yours which is leaking as hell(no offense)
 
Level 22
Joined
Aug 27, 2013
Messages
3,973
I`m Using the System which was came with Bribe`s DDS i think it`s name is " IS Unit Moving" it has it`s own Event very easy to use it is MUI , you can change it`s code a little bit for some special circumstances like adding a boolean as a flag to system to determine whether unit is walking or it just getting knockbacked the system`s code itself is more complex than yours but its 100% working and its very easy to use EventMoving =1 means moving and Eventmoving = 2 means stoped moving :D it`s more Efficient to use this system over yours which is leaking as hell(no offense)
It's leaking? Nah, that's not the point. And didn't he just remove the leaks?
It's just a matter of effectiveness.
As Nestharus said previously.
Yea, you can detect whether a unit is moving or not pretty easily with GetUnitX and GetUnitY , but that by itself is not necessarily useful. It's all of the other features that use that as a core that are useful : ).

At least those who aren't aware that they can detect whether a unit is moving or not with GetUnitX and GetUnitY can get the idea.
 
Status
Not open for further replies.
Top