This is an old revision of the document!
⇐ Index
MoveTowardsAndAvoid(<-start <-target <-delta <-minHeight <-checkRange <-checkCreeper <-checkAC <-checkPseudoTerrain) ->pos
Takes a starting 3D position (a vector) and generates a new 3D position that is moved towards the target (a vector). The resulting point will not be displaced more than the delta argument.
All forms of this API besides MoveTowards have “gravity” included. The value of this “gravity” is most certainly 0.101) and is how units that use these API's still “fall” even without applying some kind of vertical motion using another MoveTowards API independently.
Imagen that all MoveTowards API's create a 3-Vector version of the provided delta as (Dx Dy Dz) while in the process of calculating the next position. The sum of all 3 vectors (without allowing subtraction to occur) will be equal to the originally provided delta. For all of these API's except MoveTowards, Dy will have 0.1 subtracted2) from it to mimic the downwards force of gravity.
If Dy > 0, the unit will rise vertically.
If Dy < 0, the unit will fall until it reaches <-minHeight above the terrain as utilized.
The resulting Dy will be the vertical change of the unit at any time. So if your <-delta was 0.5 and the vector of direction was perfectly and only upwards, the V3 delta would be (0 0.4 0) and cause your unit to move upwards at a rate of 0.4 cells per frame.
#Move a unit towards a destination and crawl over creeper, anticreeper, and shields GetTerrainVector(42 23) ->target 0.1 ->speed 1 ->minHeight SetUnitPosition(self MoveTowardsAndAvoid(GetUnitPosition(self) <-target <-speed <-minHeight 1 true true true))
⇐ Index