issue with circle pong collision detection

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
narradream
Prole
Posts: 3
Joined: Thu Sep 21, 2017 11:52 am

issue with circle pong collision detection

Post 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
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: issue with circle pong collision detection

Post 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.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
narradream
Prole
Posts: 3
Joined: Thu Sep 21, 2017 11:52 am

Re: issue with circle pong collision detection

Post 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).
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: issue with circle pong collision detection

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
narradream
Prole
Posts: 3
Joined: Thu Sep 21, 2017 11:52 am

Re: issue with circle pong collision detection

Post by narradream »

I think I found the issue for doing collision here https://stackoverflow.com/questions/630 ... 20#6312520
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 3 guests