Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

lua

lua-5.4

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 Visual Studio Code, it said that it was "discontinued" and deprecated. Is there a sort of way to fix this problem or is there a simple substitute of this situation?

like image 433
JV I Avatar asked Oct 19 '25 10:10

JV I


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))
like image 164
Piglet Avatar answered Oct 22 '25 04:10

Piglet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!