Skip to content

Instantly share code, notes, and snippets.

@xIvan0ff
Created December 24, 2022 12:48
Show Gist options
  • Save xIvan0ff/6b7c0c3c6ed83e647f69421e8fc5d54d to your computer and use it in GitHub Desktop.
Save xIvan0ff/6b7c0c3c6ed83e647f69421e8fc5d54d to your computer and use it in GitHub Desktop.
---------------------------------------------
--[[
Utility method to get the position in front of a creature.
orientation: WoW's orientation is a radian, because WoW's circle starts at
the top we need the radian_start to make sure we're counting from the top.
This is typically the orientation of the calling unit.
yards: The distance in front of the unit to target.
useLandHeight: If true will attempt to get the X, Y map height at the
target position for the Z axis.
]] ---------------------------------------------
local RadiansConvConstant = math.pi / 180
local RadianStart = 0.5 * math.pi
function GetPositionRelative(self, orientation, yards, useLandHeight)
local UNIT_RADIANS = RadianStart + orientation
-- WoW has switched the x and y axis, x is from bottom to top, y from right to left
-- meaning y counts up if going to left, counts down if going to right, x counts up top, bottom: down
-- multiply by the yards we want to move as it'll return a number based on a circle which consists of 1 to each side (unit circle?)
local UNIT_Y = math.cos(UNIT_RADIANS) * -yards
local UNIT_X = math.sin(UNIT_RADIANS) * yards
if useLandHeight then
return self:GetX() + UNIT_X, self:GetY() + UNIT_Y,
self:GetMap():GetHeight(self:GetX() + UNIT_X, self:GetY() + UNIT_Y), self:GetO()
else
return self:GetX() + UNIT_X, self:GetY() + UNIT_Y, self:GetZ(), self:GetO()
end
end
function DegreesToRadians(degrees)
return degrees * RadiansConvConstant
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment