I've noticed a lot of posts in the Triggers section about persistent unit movement (like those related to physics systems.) I'm not going to go into a physics system because it's too advanced for a mini-tutorial and, frankly, there's already a tutorial about that. This will be a basic introduction into such a system at best. You will be instructed on how to create an "ice rink" which causes units that step onto it to be propelled in the direction that they are moving until they reach the other side. Completion of this tutorial should provide you with a basic understanding of the following concepts:
Regions: How to place a region to act as a "skating rink" and how to reference that region with triggers.
Triggers: Basic triggering skills including the use of loops for moving a unit and action definitions.
Implementation: Making your triggers work for multiple players and units.
Step 1 is, of course, to create a new map. For the purposes of this tutorial it doesn't matter what your map looks like so just pick any settings you are comfortable with as long as you are creating a MAP, not a MOD. I recommend keeping it on the smaller side (less than 128x128) to reduce loading times.
Once your map is loaded in the editor, open up the terrain editor and apply texture to a square patch of ground to distinguish it from the surrounding terrain. This will be your "ice rink."
Open up the region editor and place a region completely over your ice rink. Press ESC to get out of placement mode, then double-click on the region you just created and rename it to "Ice Rink".
In the unit editor, place a Terran Marine on your map for player 1. Put it somewhere outside of the ice rink.
At this stage, you should have created a patch of texture on the ground in the shape of a square which appears different from the surrounding texture. You should have placed a region over said patch and renamed it to "Ice Rink". Finally, you should have placed a marine for player 1 somewhere outside of the "Ice Rink".
Before we dive straight into trigger creation I'd like to go over some concepts that will aid you in your understanding of what's going on:
I understand that not everyone approaching the trigger editor is a programmer. Heck, I'm not a programmer. But having a basic understanding of certain programming concepts will give you a huge advantage in making SC2 maps. One of these concepts is called a loop.
A loop is basically a big circle that the computer processes through. Loops are incredibly useful because they can save you a lot of time when you are writing triggers. An infinite loop looks something like this:
Once this loop is activated, the game will continuously repeat the message "I'm loopy!" after every second of game-time that passes. Generally you want to avoid using infinite loops unless you put them in their own separate threads - something I will discuss soon. Often, however, you will want to restrict your loops to certain conditions. The Galaxy Editor provides several useful actions that help you accomplish this:
For/Pick Each Integer: If you want to make the game count sequentially from 1 to 10, you could use this:
General-Pickeachintegerfrom1to10,anddo(Actions)ActionsUI-Display(Combine("There are ",(Text((Pickedinteger)))," Zerglings in the pot!"))for(Allplayers)toSubtitleareaGeneral-Wait1.0GameTimesecondsOncethegamereaches10itwillstop.Ifyouwanttouseavariableinsteadof"picked integer"youcanusetheForEachIntegeraction.
For/Pick Each Player: Same as For/Pick Each Integer except that it uses players from a player group
Repeat X Times: Repeats the loop for the number of times specified
While Loop: Repeats the loop so long as the prescribed conditions are met
Each trigger in Starcraft 2 runs in its own "thread." The best way to describe threads is to think of a length of string which is comprised of many tiny threads. All of your triggers together represent the string, with each individual trigger being a thread. At any given point on the string you have many threads gathered together - just like at any given point in your game you can have many different triggers firing at once.
Why is this important? Well, sometimes you want to have a loop that goes on for a very long time and you don't want it to interrupt the rest of a trigger. When this happens, the best solution (usually) is to put that loop in its own thread. This will allow the game to continue processing the trigger that activated the loop while the loop is actually happening. In essence, you are allowing SC2 to multi-task.
To put a loop into its own thread, you need to make use of Action Definitions.
Action Definitions are another useful tool for saving time while writing triggers. They allow you to define certain parameters which can affect the actions they contain. They also have a lot of options that you can manipulate to change how the AD works. I won't go into these options in this tutorial - the most important one for us is the "Create Thread" option. If you've read the last part of this tutorial, what this option does should be obvious.
To put it simply, an Action Definition is a collection of actions (big surprise, I know.)
Alright, now let's begin making some triggers.
Open up the trigger editor. First things first, delete the Melee Initialization trigger. It will only get in the way.
Create an Action Definition and call it "Slide Movement."
Under options, check "Create Thread."
Add three parameters:
Slider = No Unit <Unit>
Direction = 0.0 <Real>
Speed = 0.0 <Real>
Under actions, create a While Loop.
Under the conditions for the While Loop, add "Unit In Region," setting Unit to the parameter Slider you created and the region to Ice Rink. Set the right hand side of the equation to True.
Under the actions for the While Loop, add a Move Unit (instantly) action. Set the unit to Slider, the point to Point with Polar Offset (using Position of (Slider), offset by (Speed / 10) toward Direction,) Blend.
Still under the actions for the While Loop, add "Wait 0.05 game-time seconds".
Create a new event using event type Unit Enters Region, setting the unit to Any Unit and the region to "Ice Rink", which you created at the beginning of the tutorial.
Under actions, add an Issue Order function. We need to tell the marine to Stop when he hits the ice or the game's AI will cause problems. Your function should read "Unit - Order (Triggering unit) to ( Stop) (Replace Existing Orders)."
Create a new action and look under the General assortment. You should see Slide Movement. Select this and click on OK.
Set the parameters to the following:
Slider: (triggering unit)
Direction: (facing angle of (triggering unit)) #This uses the Facing of Unit function#
Speed: (Triggering unit) Movement Speed (current) #This uses the Unit Property function#
Create a new action after Slide Movement which displays a message to the player. Something like "OH NOOOOOO!" might be appropriate. I also recommend playing the marine's death sound for extra fun.