Game Maker Language リファレンス > 組み込み関数 用途別 > 数値計算・文字列・日付/時間 > arctan2
arctan2(x,y)
arctan(y/x)の値を-π〜+πで返す。
xとyを指定することによって、全方位をカバーするアークタンジェントを返します。
r = round(radtodeg(arctan2(-1,-1))); /* r is -135 */
Objectのscriptで以下のように記述する
dx = mouse_x - x dy = mouse_y - y // calc direction direction = radtodeg(arctan2(-dy, dx)) // calc speed length = sqrt(sqr(dx) + sqr(dy)) speed = 5 * length / 100
ただし目的への角度を取得するだけなら、point_direction()で代用できる。
// calc direction direction = point_direction(x, y, mouse_x, mouse_y); // calc speed length = point_distance(x, y, mouse_x, mouse_y); speed = 5 * length / 100