Difference between revisions of "Detecting if a unit is in water"

From HIVE
Jump to navigation Jump to search
 
Line 7: Line 7:
 
Periodically checking the height of the units is a rather inefficient way of doing it, especially if you have many units doing it. An alternate method, assuming that the water on your map is very cleanly made, is to simply place regions over the water and checking if a unit enters those regions. This could be very time-consuming for complex water patterns and is generally not recommended (it looks unnatural; however, if you are, for example, only using water near man-made land (temple, etc), linear may be just what you need).
 
Periodically checking the height of the units is a rather inefficient way of doing it, especially if you have many units doing it. An alternate method, assuming that the water on your map is very cleanly made, is to simply place regions over the water and checking if a unit enters those regions. This could be very time-consuming for complex water patterns and is generally not recommended (it looks unnatural; however, if you are, for example, only using water near man-made land (temple, etc), linear may be just what you need).
  
===Exemple map===
+
===Example map===
 
Download [http://www.staredit.net/?attachment=7292 this map] and open it in [[GalaxyEdit]] to see the final result of this system.
 
Download [http://www.staredit.net/?attachment=7292 this map] and open it in [[GalaxyEdit]] to see the final result of this system.
  

Latest revision as of 01:15, 15 December 2010

Detecting if a unit is in water may seem tricky, because there is no tool in the trigger editor to help us work with water as it exists in StarCraft II. However, with some manual effort and a simple technique, it's possible to detect if a unit is in water and utilize that information for almost any scenario.

The key to detecting if a unit is in water is detecting the height it's at. A piece of terrain is under water if there's a water tile on it, and if the "Height at point" of the piece of terrain is less than the height of the water tile. A ground unit is under the water if its "Height at point: Position of unit" is less than the height of the water, and a flying unit is under the water if its "Height at point: Position of unit" (detects terrain level) + "Height of unit" (detects flying unit height above ground) is below the level of the water.

If you use only one type of water on your map and there are no points below a certain height that are not filled with water, then all you have to do is periodically check if the height of the unit (or the sum of the two height functions) is below the height of the water. If you have different waters, or if you have water at a height at one point but you go below that height at another point, then you have to mix in detecting the region that the unit is in, which would, for most cases, be fairly simple. It's the exact same thing if you have different waters.

Periodically checking the height of the units is a rather inefficient way of doing it, especially if you have many units doing it. An alternate method, assuming that the water on your map is very cleanly made, is to simply place regions over the water and checking if a unit enters those regions. This could be very time-consuming for complex water patterns and is generally not recommended (it looks unnatural; however, if you are, for example, only using water near man-made land (temple, etc), linear may be just what you need).

Example map

Download this map and open it in GalaxyEdit to see the final result of this system.