How do i type an arc tangent in lua 5.4 if the math.atan2 is

Viewed 469

i'm trying to use the math.library on Lua (version 5.4) and i tried to use the math.atan2 here:

math.randomseed (os.time())

local Player_x, Player_y = 400,300
local Enemy_x = math.random (0,800)
local Enemy_y = math.random (0,600)
local angle = math.atan2((Enemy_y - Player_y), (Enemy_x - Player_x))
local angle_degree = math.deg (angle)


print (Enemy_x..","..Enemy_y)
print ("The angle from Enemy to the Player: "..angle_degree.." degree.")

But when i tried to put run on my VSCode, it says that it was "discontinued" and deprecated. Any sort of ways to fix this problem or a simple substitute of this situation.

1 Answers

math.atan2 was deprecated in Lua 5.3

https://www.lua.org/manual/5.3/manual.html#8.2

The following functions were deprecated in the mathematical library: atan2, cosh, sinh, tanh, pow, frexp, and ldexp. You can replace math.pow(x,y) with x^y; you can replace math.atan2 with math.atan, which now accepts one or two arguments; ...

local angle = math.atan((Enemy_y - Player_y), (Enemy_x - Player_x))
Related