Page 1 of 1

issue with circle pong collision detection

Posted: Thu Sep 21, 2017 11:57 am
by narradream
SO, I made the following simple circle pong toy. I am having issues with getting the correct angle . I'm getting negative values for the top-half of the circle ?! how can I just get 0 -> 360 ?!
https://github.com/Sweetkubuni/circle_pong

Re: issue with circle pong collision detection

Posted: Fri Sep 22, 2017 1:39 pm
by davisdude
In your function LineAngle, replace math.atan with math.atan2 and replace the division sign with a comma.

Specifically, note the differences between the parameters for math.atan and math.atan2 in the Lua 5.1 documentation. Also note that math.atan2 was deprecated in 5.3 (emphasis mine):
Lua 5.3 Reference Manual wrote: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 parameters; you can replace math.ldexp(x,exp) with x * 2.0^exp. For the other operations, you can either use an external library or implement them in Lua.
LOVE uses LuaJit, which is compatible with Lua 5.1, so it shouldn't be an issue. Just something to be aware of.

Re: issue with circle pong collision detection

Posted: Sat Sep 23, 2017 2:08 pm
by narradream
davisdude wrote: Fri Sep 22, 2017 1:39 pm In your function LineAngle, replace math.atan with math.atan2 and replace the division sign with a comma.

Specifically, note the differences between the parameters for math.atan and math.atan2 in the Lua 5.1 documentation. Also note that math.atan2 was deprecated in 5.3 (emphasis mine):
Lua 5.3 Reference Manual wrote: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 parameters; you can replace math.ldexp(x,exp) with x * 2.0^exp. For the other operations, you can either use an external library or implement them in Lua.
LOVE uses LuaJit, which is compatible with Lua 5.1, so it shouldn't be an issue. Just something to be aware of.
I did what you suggest. Though, I think atan2 takes the arguments as atan2(x,y) ; anyway, I tried running the folder on lovec.exe, but whenever the ball hits the circle my game crashes (well stops).

Re: issue with circle pong collision detection

Posted: Sat Sep 23, 2017 2:17 pm
by zorg
atan2 takes arguments in the order of y,x; as a matter of fact; you may be expecting 0 degrees/radians to point in a direction other than it actually does, though.

Re: issue with circle pong collision detection

Posted: Tue Sep 26, 2017 1:06 pm
by narradream
I think I found the issue for doing collision here https://stackoverflow.com/questions/630 ... 20#6312520