有谁知道它应该是什么角度?

Does anyone know what angle it should be?

我有一个游戏,玩家的射击工作正常,但那是因为我使用了 on.click 事件和一些数学,但现在我正试图让敌人射击回到我的播放器。

我只是敌人,所以me.xme.y是敌人的x和y。

p 是玩家所以 p.xp.y 是玩家的 x 和 y。

我们正在尝试从 me.xm.y 拍摄到 p.xp.y

按照现在的代码,它只是每秒向右随机射击。

canvas 为 500x500。

me.angle = Math.atan2(p.x, p.y) / Math.PI * 180;

 me.fireBullet = function (angle) {
  var b = Bullet(me.id, angle); //bullet id, with angle pack
   b.x = me.x;
   b.y = me.y;
  }

   setInterval(function () {
     me.fireBullet(me.angle); //target angle attack
     }
       , 1000);
    }
 tan(angle) =  y / x  | arctan()
 angle = arctan(x / y)

现在我们只需要获取从玩家到敌人的向量的 x 和 y:

angle = Math.atan( (me.x - p.x) / m(e.y - p.y)) || 0;

解决方法是找出 x 和 y 之间的差异,我尝试了几次,但现在可以了。

var differenceX = p.x - me.x; //players x - targets x
var differenceY = p.y - me.y; //players y - targets y

me.angle = Math.atan2(differenceY, differenceX) / Math.PI * 180