オブジェクトを常にプレーヤーに向けようとしていますが、その背後にある数学に苦労しています。これまでのところ、オブジェクトはプレーヤーが移動しても回転しますが、一貫性がありません。
これは、オブジェクトを回転させるために使用するものです。
var targetX = player.x - this.width/2;
var targetY = player.y - this.height/2;
this.rotation = Math.atan2(targetY, targetX);
ctx.transform(1, 0, 0, 1, this.x, this.y);
//ART WORK
ctx.save()
ctx.translate(15, 15);
ctx.rotate(this.rotation);
ctx.fillStyle = "866c4a";
ctx.fillRect(-15, -15, this.width, this.height);
ctx.restore();
私が言ったように、それは正しく機能しません。それは私の数学に関係していると思います。
ありがとう