The math surely need to be improved!
Thanks for the comment, i've made a major upgrade. Tweeked the math a bit too. Working on a new game now, will release it soon on a game jam (hopefully :) ).