Just chiming in here. The problem is specifically caused by the square root becoming negative at line 50, i.e.
local dy = (ranSign*math.sqrt((customEmitter.radiusRange*customEmitter.radiusRange) - ((dx - ex)*(dx - ex)))) + ey
If (dx - ex)*(dx - ex)
is larger than customEmitter.radiusRange*customEmitter.radiusRange
, then you’ll get -nan(ind)
, which crashes the transition.to
call.
The proper way to fix this is to rethink your function, i.e. what should happen in those instances, or to ensure the value inside the square root is never negative, for example:
local dy = ranSign*math.sqrt( math.max( 0, customEmitter.radiusRange*customEmitter.radiusRange - (dx - ex)*(dx - ex) ) ) + ey
On an unrelated note, I understand this is some old code you just dug up, but given how this seems like something you’d be calling repeatedly, you may want to do some minor optimisation. For instance, you could create a local radiusRange
variable inside the emit
function so that you only need to do 1 table lookup instead of 8.
You’re also setting a bunch of variables to nil inside the transition’s onComplete listener, but that’s unnecessary. Setting customEmitter
or group
to nil only makes the references to these tables nil, i.e. the actual tables still persist. As for all of the other variables that are local to the emit
function, they get cleaned up automagically when the function finishes as there will be no more references left to them.