Hi guys!
I came across something very strange that did not happen to me.
if I do an operation inside math.round with numbers near 0 this returns me “-1.#IND”.
if instead I calculate after using round I get 0 (which is right)
To explain myself better, I have extrapolated the code. Leaving aside the use that I do try first the function test1 (everything goes according to plan) and test2 (error).
as you can see from test1 to test2 change ONLY the function foo:
fisrt:
local dx, dy = x-var1, y-var2 local ccgm = staticVal / sqrt(dx^2 + dy^2) dx, dy = round(dx), round(dy)
second:
local dx, dy = round(x-var1), round(y-var2)
below all the code to perform the tests(call test1 first and look at the console when right reaches 0 and then do the same thing with test2):
local function test1() local static1 = 140 local static2 = 300 local sqrt = math.sqrt local round = math.round local staticVal = 15 local var1=180 local var2=300 local function foo (x, y) local dx, dy = x-var1, y-var2 local ccgm = staticVal / sqrt(dx^2 + dy^2) dx, dy = round(dx), round(dy) print(dx,dy) return dx\*ccgm, dy\*ccgm end local now = system.getTimer( ) timer.performWithDelay(30, function(event) local time = event.time local dt = (time - now) / 1000 now = time local vx,vy = foo(static1, static2) var1 = (var1+(dt\*vx)) end,-1) end local function test2() local static1 = 140 local static2 = 300 local sqrt = math.sqrt local round = math.round local staticVal = 15 local var1=180 local var2=300 local function foo2(x, y) local dx, dy = round(x-var1), round(y-var2) --local dx dy = x-var1, y-var2 local ccgm = staticVal / sqrt(dx^2 + dy^2) print(dx,dy) return dx\*ccgm, dy\*ccgm end local now = system.getTimer( ) timer.performWithDelay(30, function(event) local time = event.time local dt = (time - now) / 1000 now = time local vx,vy = foo2(static1, static2) var1 = (var1+(dt\*vx)) end,-1) end --test1() --test2()