4rpl:commands:movetowardsandavoid

This is an old revision of the document!


Index

MoveTowardsAndAvoid

MoveTowardsAndAvoid(<-start <-target <-delta <-minHeight <-checkRange <-checkCreeper <-checkAC <-checkPseudoTerrain) ->pos

Description

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.

  • The minHeight argument restricts how close, height wise, the resulting point can be to the terrain and/or creeper.
  • The checkRange argument is an integer that specifies how many cells outward to inspect when enforcing the minHeight. A value of 0 means to only check the map cell that the target is currently within on.
  • The checkCreeper argument is a Boolean indicating whether to look at creeper for enforcing the minHeight.
  • The checkAC argument is a Boolean indicating whether to look at anticreeper for enforcing the minHeight.
  • The checkPseudoTerrain argument is a Boolean indicating whether to look at invisible pseudo terrain (like a shield creates) for enforing the minHeight.

:WARNING:
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.

Examples

#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

1)
Derived from how there is no “gravity” for a unit when using these API's for moving only upwards (when the unit is told to move to it's current cell at a specific height). Any lower movement than 0.10 cells upwards would cause the unit to slowly fall down until minHeight stops it and does so at a speed dependent on how much lower the vertical change is to 0.10 as this “gravity” will be “stronger” than the unit's ability to move upwards, causing it to fall with minHeight being an intervention in this process.
2)
However, I possess no confirmation to if this subtraction is factored in how Dx + Dy + Dz = <-delta for if it wasn't, the unit would not move by <-delta at most and not be the true maximum delta. Either it moves no more but never equal to <-delta or moves at most by ~exactly <-delta (which is currently what was and is being assumed).
4rpl/commands/movetowardsandavoid.1648761721.txt.gz · Last modified: 2025/02/14 14:56 (external edit)