Hello there! We are conducting a survey to better understand the user experience in making a first edit. If you have ever made an edit on Gamepedia, please fill out the survey. Thank you!

API UnitPosition

From Wowpedia
Jump to: navigation, search

Returns the position of a unit within the current world area.

posY, posX, posZ, instanceID = UnitPosition("unit");


String - The unitId for which the position is returned. Does not work with all unit types. Works with "player", "partyN" or "raidN" as unit type. In particular, it does not work on pets or any unit not in your group.


posY, posX, posZ, instanceID
Number - Y value of the unit's position in yards, relative to the instance.
Number - X value of the unit's position in yards, relative to the instance.
Number - Always 0. A placeholder for the Z coordinate.
Number - ID of the instance map that the unit is currently on.


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


Returns the distance in yards between 2 units in the same raid, or nil if they're not in the same instance.

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.

Patch changes