Tutorial Make Units Slide

Ryuu

I am back with Chocolate (:
Reaction score
64
Flare's GUI MUI method is used.

GUI
First off, define which event you need. Will it be when you cast a spell and you slide to the target point? In this tutorial I'll be using the 'starts the effect of an ability' event.

Trigger:
  • Events
    • Unit - A unit Starts the effect of an ability

The condition below checks if the unit casts the 'slide' spell.

Trigger:
  • Conditions
    • (Ability being cast) Equal to Slide

So now that you initialized the trigger, we got to start with the core part - the actions.

This is what your trigger should look like for the time being:

Trigger:
  • Slide Init
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Slide
    • Actions

First off, we need to set variables to use them for later. These variables are needed:

1. CustomValue (Integer Non-array Variable)
2. SlidePoint (Point Array Variable)
3. Slider (Unit Array Variable)
4. SlideOffset (Point Array Variable)
5. UnitGroup (Unit Group Non-array Variable)
6. TmpInteger (Integer Non-array Variable)
7. MovedRange (Real Array Variable)
8. TargetPoint (Point Array Variable)
9. StartPoint (Point Array Variable)​

Usually after we initialize variables, we set them in the trigger. However in this case, since we are doing a MUI sliding, we got initialize the MUI section first. The following action checks if the CustomValue variable reaches 100; if it does reach 100 or higher, it recycles the indices so that the spell actually becomes MUI.

Trigger:
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • CustomValue Less than 100
      • Then - Actions
        • Set CustomValue = (CustomValue + 1)
      • Else - Actions
        • Set CustomValue = 1


Then we set the variables. Notice in the following code that I use CustomValue as the index for our array variables. This fulfills the purpose of having a CustomValue variable, making our spell MUI.

Trigger:
  • Actions
    • Set Slider[CustomValue] = (Triggering unit)
    • Set StartPoint[CustomValue] = (Position of Slider[CustomValue])
    • Set SlidePoint[CustomValue] = (Position of Slider[CustomValue])
    • Set TargetPoint[CustomValue] = (Target point of ability being cast)

Now that we set our variables, we need to give one of our units the custom value CustomValue. This also fulfills the purpose of making our spell MUI. However do realise that you don't have to have a model-less dummy unit for our spell. All we need is a peasant. I rather you choose the frog.

Also, if you don't want our unit to be seen, you can specify a hidden region in our map or just give our unit no model.

Trigger:
  • Actions
    • Unit - Create 1 Frog (No model) for (Owner of Slider[CustomValue]) at SlidePoint[CustomValue] facing Default building facing degrees

Next we need to give him the custom value, and add him to our unit group.

Trigger:
  • Actions
    • Unit - Set the custom value of (Last created unit) to CustomValue
    • Unit Group - Add (Last created unit) to UnitGroup

The last action, simply removing leaks.

Trigger:
  • Custom script: call RemoveLocation(udg_SlidePoint[udg_CustomValue])

We're done for this initialization trigger.
This is what your trigger should look like:

Trigger:
  • Slide Init
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Slide
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CustomValue Less than 100
        • Then - Actions
          • Set CustomValue = (CustomValue + 1)
        • Else - Actions
          • Set CustomValue = 1
      • Set Slider[CustomValue] = (Triggering unit)
      • Set StartPoint[CustomValue] = (Position of Slider[CustomValue])
      • Set SlidePoint[CustomValue] = (Position of Slider[CustomValue])
      • Set TargetPoint[CustomValue] = (Target point of ability being cast)
      • Unit - Create 1 Frog for (Owner of Slider[CustomValue]) at SlidePoint[CustomValue] facing Default building facing degrees
      • Unit - Set the custom value of (Last created unit) to CustomValue
      • Unit Group - Add (Last created unit) to UnitGroup
      • Custom script: call RemoveLocation(udg_SlidePoint[udg_CustomValue])

Now that we're done with our initialization trigger, it's time we really go in to our core trigger. Create a new trigger, with the event:

Trigger:
  • Events
    • Time - Every 0.03 seconds of game time

You can change the above value to your liking. However don't go above 0.04, it will be quite unrealistic.

Next off we need to specify the conditions. The following condition checks if anyone even cast the 'Slide' spell. Because if this trigger is running unused for a long period, the game might get laggy.

Trigger:
  • Conditions
    • CustomValue Greater than 0

Now the actions. Before doing anything we need to use the ForGroup call.
Translated to GUI is this:

Trigger:
  • Actions
    • Unit Group - Pick every unit in UnitGroup and do (Actions)
      • Loop - Actions

The following action is probably useless but it can save you a lot of time. Instead of referring back to '(Custom value of (Picked unit))' for the entire trigger, you can just refer back to the TmpInteger variable.

Trigger:
  • Actions
    • Set TmpInteger = (Custom value of (Picked unit))

The following action checks if the slider is dead. Because we don't want sliding corpses.

Trigger:
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Slider[TmpInteger] is dead) Equal to True
      • Then - Actions
        • Unit - Remove (Picked unit) from the game
      • Else - Actions

Under 'Else - Actions', set the following variables. The following actions are 'setups' for the main action. The '15' in the second action is the speed of sliding. Basically it moves every 15 units per 0.03 second.

Trigger:
  • Actions
    • Set SlidePoint[TmpInteger] = (Position of Slider[TmpInteger])
    • Set SlideOffset[TmpInteger] = (SlidePoint[TmpInteger] offset by 15.00 towards (Angle from SlidePoint[TmpInteger] to TargetPoint[TmpInteger]) degrees)

The following actions check if the unit has reached its point. There are also leak removals because we are going to recycle the variables, hence we can't leave any of them lying around.

Trigger:
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • MovedRange[TmpInteger] Less than (Distance between StartPoint[TmpInteger] and TargetPoint[TmpInteger])
      • Then - Actions
        • Unit - Move Slider[TmpInteger] instantly to SlideOffset[TmpInteger]
        • Set MovedRange[TmpInteger] = (MovedRange[TmpInteger] + 15.00)
        • Custom script: call RemoveLocation(udg_SlidePoint[udg_TmpInteger])
        • Custom script: call RemoveLocation(udg_SlideOffset[udg_TmpInteger])
      • Else - Actions
        • Unit - Remove (Picked unit) from the game
        • Unit - Order Slider[TmpInteger] to Stop
        • Set Slider[TmpInteger] = No unit

Getting out of the If/Then/Else, we need to remove the leaks.

Trigger:
  • Actions
    • Custom script: call RemoveLocation(udg_SlidePoint[udg_TmpInteger])
    • Custom script: call RemoveLocation(udg_SlideOffset[udg_TmpInteger])
    • Custom script: call RemoveLocation(udg_StartPoint[udg_TmpInteger])
    • Custom script: call RemoveLocation(udg_TargetPoint[udg_TmpInteger])


That's it! You're done with your GUI sliding.
Your second trigger should look like this:

Trigger:
  • Slide
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
      • CustomValue Greater than 0
    • Actions
      • Unit Group - Pick every unit in UnitGroup and do (Actions)
        • Loop - Actions
          • Set TmpInteger = (Custom value of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Slider[TmpInteger] is dead) Equal to True
            • Then - Actions
              • Unit - Remove (Picked unit) from the game
            • Else - Actions
              • Set SlidePoint[TmpInteger] = (Position of Slider[TmpInteger])
              • Set SlideOffset[TmpInteger] = (SlidePoint[TmpInteger] offset by 15.00 towards (Angle from SlidePoint[TmpInteger] to TargetPoint[TmpInteger]) degrees)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • MovedRange[TmpInteger] Less than (Distance between StartPoint[TmpInteger] and TargetPoint[TmpInteger])
                • Then - Actions
                  • Unit - Move Slider[TmpInteger] instantly to SlideOffset[TmpInteger]
                  • Set MovedRange[TmpInteger] = (MovedRange[TmpInteger] + 15.00)
                  • Custom script: call RemoveLocation(udg_SlidePoint[udg_TmpInteger])
                  • Custom script: call RemoveLocation(udg_SlideOffset[udg_TmpInteger])
                • Else - Actions
                  • Unit - Remove (Picked unit) from the game
                  • Unit - Order Slider[TmpInteger] to Stop
                  • Set Slider[TmpInteger] = No unit
              • Custom script: call RemoveLocation(udg_SlidePoint[udg_TmpInteger])
              • Custom script: call RemoveLocation(udg_SlideOffset[udg_TmpInteger])
              • Custom script: call RemoveLocation(udg_StartPoint[udg_TmpInteger])
              • Custom script: call RemoveLocation(udg_TargetPoint[udg_TmpInteger])

GUI sliding triggers
Code:
Slide Init
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Slide 
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                CustomValue Less than 100
            Then - Actions
                Set CustomValue = (CustomValue + 1)
            Else - Actions
                Set CustomValue = 1
        Set Slider[CustomValue] = (Triggering unit)
        Set StartPoint[CustomValue] = (Position of Slider[CustomValue])
        Set SlidePoint[CustomValue] = (Position of Slider[CustomValue])
        Set TargetPoint[CustomValue] = (Target point of ability being cast)
        Unit - Create 1 Frog for (Owner of Slider[CustomValue]) at SlidePoint[CustomValue] facing Default building facing degrees
        Unit - Set the custom value of (Last created unit) to CustomValue
        Unit Group - Add (Last created unit) to UnitGroup
        Custom script:   call RemoveLocation( udg_SlidePoint[udg_CustomValue] )

Code:
Slide
    Events
        Time - Every 0.03 seconds of game time
    Conditions
        CustomValue Greater than 0
    Actions
        Unit Group - Pick every unit in UnitGroup and do (Actions)
            Loop - Actions
                Set TmpInteger = (Custom value of (Picked unit))
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Slider[TmpInteger] is dead) Equal to True
                    Then - Actions
                        Unit - Remove (Picked unit) from the game
                    Else - Actions
                        Set SlidePoint[TmpInteger] = (Position of Slider[TmpInteger])
                        Set SlideOffset[TmpInteger] = (SlidePoint[TmpInteger] offset by 15.00 towards (Angle from SlidePoint[TmpInteger] to TargetPoint[TmpInteger]) degrees)
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                MovedRange[TmpInteger] Less than (Distance between StartPoint[TmpInteger] and TargetPoint[TmpInteger])
                            Then - Actions
                                Unit - Move Slider[TmpInteger] instantly to SlideOffset[TmpInteger]
                                Set MovedRange[TmpInteger] = (MovedRange[TmpInteger] + 15.00)
                                Custom script:   call RemoveLocation(udg_SlidePoint[udg_TmpInteger])
                                Custom script:   call RemoveLocation(udg_SlideOffset[udg_TmpInteger])
                            Else - Actions
                                Unit - Remove (Picked unit) from the game
                                Unit - Order Slider[TmpInteger] to Stop
                                Set Slider[TmpInteger] = No unit
                        Custom script:   call RemoveLocation(udg_SlidePoint[udg_TmpInteger])
                        Custom script:   call RemoveLocation(udg_SlideOffset[udg_TmpInteger])
                        Custom script:   call RemoveLocation(udg_StartPoint[udg_TmpInteger])
                        Custom script:   call RemoveLocation(udg_TargetPoint[udg_TmpInteger])
 

UndeadDragon

Super Moderator
Reaction score
447
I have no guarantee the vJass one works.

Maybe you should check that before posting it :p

A lengthy tutorial you have made here. I am sure that the many people who ask questions about "How do I make a unit slide" will be able to find out using this tutorial.
 

Ryuu

I am back with Chocolate (:
Reaction score
64
I have no guarantee over that one because I haven't tested it myself. Or rather I had no chance to test it.
 

Flare

Stops copies me!
Reaction score
662
Code:
# Set StartPoint[CustomValue] = (Position of Slider[CustomValue])
# Set SlidePoint[CustomValue] = StartPoint[CustomValue]
What's the point in that? Also, when you do
Code:
Custom script: call RemoveLocation(udg_SlidePoint[udg_CustomValue])
You're also destroying StartPoint[CustomValue], since you're destroying the location that SlidePoint is pointing to, and that location is StartPoint
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
You should test anything before making a tutorial for ANYTHING!

fyi - that's a bad way of making a unit slide in vJASS refer to your JassHelper manual for more information :p
 

Ryuu

I am back with Chocolate (:
Reaction score
64
The vJass part was made to the extent of my knowledge. However I will either test it later or tomorrow so it shouldn't be so bad.

Flare
I didn't know that, thanks. Fixed.​
 

saw792

Is known to say things. That is all.
Reaction score
280
Wow umm... ok then.

Maybe you should just skip the vJASS part for now, since anybody who understands it doesn't need it, and people who don't shouldn't be learning that way (unoptimized, inefficient, BJ-filled, UnitUserData-hogging tripe). No offence intended towards you, of course, I just think it's better to stick with what you know well, your GUI system.

The first thing to do would be to check through all your GUI code and make sure it works properly, fix up a couple of things that have been mentioned already, and then work on the vJASS. Don't use the same method you would use in GUI for vJASS, since then there is absolutely no advantage in using vJASS at all. Sooda's method is not applicable at all for this situation. You want an attachment system and a timer callback to do the work for you and keep things MUI.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top