public float loopCorrection(float input, float scale) { input %= scale; while (input < 0) { input += scale; } return input; }