Skip to content
everloot

Lore archive · Warcraft Wiki, 2023 dump

API UnitPosition

Last wiki revision 2023-01-28

Returns the position of a unit in the current world area. posY, posX, posZ, instanceID = UnitPosition(unit)

  • unit: : UnitId - The unit for which the position is returned. Does not work with all unit types. Works with, or as unit type. In particular, it does not work on pets or any unit not in your group.
  • posY: - Y value of the unit's position in yards, relative to the instance
  • posX: - X value of the unit's position in yards, relative to the instance
  • posZ: - Always 0. A placeholder for the Z coordinate
  • instanceID: - InstanceID

Returns the distance in yards between 2 units in the same raid, or nil if they're not in the same instance or are in a raid/dungeon/competitive instance. function ComputeDistance(unit1, unit2) local y1, x1, _, instance1 = UnitPosition(unit1) local y2, x2, _, instance2 = UnitPosition(unit2) return instance1 == instance2 and ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5 end

It's important to note that since this number is being measured from the center of the two units, and spell ranges are calculated from the edge of their hitbox, you will need to subtract 3 yards if you're using this function for measuring spell distance between players.

Source

https://warcraft.wiki.gg/wiki/API_UnitPosition · retrieved 2023-11-13 · CC BY-SA 4.0

Converted from wikitext with templates, tables and images removed, so some sentences may be missing values.

This archive predates WoW: Forever. For collected gameplay facts see the Forever database. Search the archive.