Calculating degrees between 2 points with inverse Y axis

前端 未结 4 1244
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 17:45

I\'m creating a simple 2D game in javascript/canvas. I need to figure out the angle of a certain object relative to my position.

So: say I\'m at (10,10) and the object i

4条回答
  •  佛祖请我去吃肉
    2021-01-31 18:31

    In layman's terms:

    function pointDirection(x1, y1, x2, y2) {
        return Math.atan2(y2 - y1, x2 - x1) * 180 / Math.PI;
    }
    

提交回复
热议问题