For some people who doesn't seem to know the purpose of detecting speed of particular unit, I will briefly explain why it has got so many uses for UMS maps.
Have you played 'Metal Gear Solid' series? What's the concept of this kind of game? "The Stealth Action", right? Now how the hell would you put stealth action into starcraft when there is no such thing like that. This is why detecting speed is important. It's because lots of stealth action games uses detecting speed to interact with environments in the game.
Here are more examples of stealth action games.
- Thief
- Hitman
- Rainbow Six
- Soldier of Fortune
- Splinter Cell
- Starcraft: Ghost
Now you know how this system might be useful for your map once you plan to make Stealth Action based map.
Ok, then how do we archieve this? There are various ways to detect speed. Hopefully, you should figure out the differences between each method.
Detecting Speed by Distance Traveled
This method detects unit's speed by evaluating the distance traveled in specific time. Let's say, in 1 sec, Unit A has moved from centre of Location 1 to the edge of Location 3 where Location 1 has size of 1x1 and Location 3 has size of 3x3. Then we can know that Unit A has moved distance from center of Location A and edge of Location 3 in 1 second.
(note: This method is applying the way we evaluate speed of some object in reality)
Detecting Speed by Distance Between Units
This method is slightly different from previous one. You can imagine this method as "Speed Camera". Speed Camera records the distance between car and itself, and after some interval, it again records the distance between car and itself, and then evaluate the speed. By applying this "Speed Camera", we can evaluate the incoming unit's speed towards specific object. For example, if the incoming unit is in the Location 3 and after some interval, it now is in the Location 1, then we can know distance it moved, therefore speed can be evaluated. But in order to do this, the unit who records the distance between incoming unit and itself SHOULD be stationary. Otherwise, it will miscalculate because you can not really evaluate the speed when two objects are moving and speed of them are unknown.
Detecting Speed by Comparing Coordinates
This is very similar to the first method. Only the difference is that we use new system called "Position Tracker" Position tracker basically, and literally, keeps a track of unit's position. But before we use this system we should know how to move location by 1 grid to any direction you want.
Try creating 12 Kakaru slowly. You can see Kakaru being created in different coordinates. Yes, it has got a pattern. First Kakaru will be created at the center of location and then second Kakaru will be created 1 grid to bottom from center of location. Next will be created 1 grid to right from position of second Kakaru created. And then It creates unit in anti-clockwise.
But using Kakaru isn't totally accurate. So we have to use Scourge as a first unit being spawned. And then rest of them will be Kakaru except for final unit that indicates the destination. Destination should be Observer in order to move location to the correct coordinate more easily.
Now if we know how to move location by 1 grid to any direction we want, then move 8 locations to each 8 directions. Assume that player's unit is at (64,64). If player unit go to location 'South' which is preplaced. Then subtract 1 from Y coordinate. And after some interval, calculate the difference between original coordinate and current coordinate. Original coordinate was (64,64) and current coordinate is now (64, 63). By knowing that unit has moved 1 grid, we can evaluate the speed.
Detecting Speed by Faster Units
This method is bit weird. You need units who can move faster than the unit you want to evaluate the speed of. Create 2 locations with size 1 X Map Height and Map Width X 1, but I will demonstrate only X direction. These two location will always follow player's unit. And at the side of map, create the straight pathway where Faster Units will move as player's unit moves. I'd recommend hero zealot for being a "Faster Unit". Place Zealots in this order
Owner: P9, P9, P10, P11, P11
Now if Location has any unit that is belong to P9 or P11 then zealots will move. P9 represents West and P11 represents East, and ofcourse, they will stop moving if Location has only unit belong to P10.
It's pretty easy to evaluate the speed from this point. You could set the condition like below.
If Location has 1 p10 unit then modify the player's speed to 0.
If Location has 1 P9 unit and 1 P10 unit then modify the player's speed to 1.
If Location has 2 P9 units then modify the player's speed to 2.
I hope you followed the right track to this point.
FYI: As always, I haven't covered small things, concepts only.
Comment
Actually method 3, 4 can be used to evaluate Velocity (Direction and Speed) of unit.